Skip to content

tres #81

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 32 commits into
base: master
Choose a base branch
from
Open

tres #81

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
20 changes: 20 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Launch Program",
"skipFiles": [
"<node_internals>/**"
],
"program": "${workspaceFolder}\\app.js",
"outFiles": [
"${workspaceFolder}/**/*.js"
]
}
]
}
1 change: 1 addition & 0 deletions Procfile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
web: node app.js
226 changes: 167 additions & 59 deletions app.js
Original file line number Diff line number Diff line change
@@ -1,59 +1,167 @@
const express = require("express");
const app = express();
const port = process.env.PORT || 3001;

app.get("/", (req, res) => res.type('html').send(html));

app.listen(port, () => console.log(`Example app listening on port ${port}!`));


const html = `
<!DOCTYPE html>
<html>
<head>
<title>Hello from Render!</title>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/confetti.browser.min.js"></script>
<script>
setTimeout(() => {
confetti({
particleCount: 100,
spread: 70,
origin: { y: 0.6 },
disableForReducedMotion: true
});
}, 500);
</script>
<style>
@import url("https://p.typekit.net/p.css?s=1&k=vnd5zic&ht=tk&f=39475.39476.39477.39478.39479.39480.39481.39482&a=18673890&app=typekit&e=css");
@font-face {
font-family: "neo-sans";
src: url("https://use.typekit.net/af/00ac0a/00000000000000003b9b2033/27/l?primer=7cdcb44be4a7db8877ffa5c0007b8dd865b3bbc383831fe2ea177f62257a9191&fvd=n7&v=3") format("woff2"), url("https://use.typekit.net/af/00ac0a/00000000000000003b9b2033/27/d?primer=7cdcb44be4a7db8877ffa5c0007b8dd865b3bbc383831fe2ea177f62257a9191&fvd=n7&v=3") format("woff"), url("https://use.typekit.net/af/00ac0a/00000000000000003b9b2033/27/a?primer=7cdcb44be4a7db8877ffa5c0007b8dd865b3bbc383831fe2ea177f62257a9191&fvd=n7&v=3") format("opentype");
font-style: normal;
font-weight: 700;
}
html {
font-family: neo-sans;
font-weight: 700;
font-size: calc(62rem / 16);
}
body {
background: white;
}
section {
border-radius: 1em;
padding: 1em;
position: absolute;
top: 50%;
left: 50%;
margin-right: -50%;
transform: translate(-50%, -50%);
}
</style>
</head>
<body>
<section>
Hello from Render!
</section>
</body>
</html>
`
import fs from 'fs-extra';

import {Conf} from './clasp/conf.js';
import {hasOauthClientSettings, safeIsOnline, saveProject} from './clasp/utils.js';
import { pushFiles } from './clasp/files.js';

import { authorize_getUrl, convertAuthCodeInToken, defaultScopes } from './clasp/auth.js';
import { googleProvisioning, createGoogleProject } from './provisioning.js';
import open from 'open';

import { launch } from 'puppeteer';
//import body-parser from 'body-parser';
import bodyParser from "body-parser";


//const express = require('express');
import express from 'express';

//const path = require('path')
import path from 'path';

import { fileURLToPath } from 'url';

const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);

//const app = express();

const port = process.env.PORT || 5004

var scriptId;

express()
.use(express.static(path.join(__dirname, 'public')))

.use(bodyParser.json())
.use(bodyParser.urlencoded({extended: true}))
.use(express.static("public"))
.set('view engine', 'ejs')

.get('/', (req, res) => { res.render('pages/index', { name: "-", tokenState: "-", momentprj: "-" })})

.get('/testAuth', async (req, res) => {

const externalHost = false;
console.log('process.env:' + process.env.port);

const automatic = true;
const authUrl = await authorize_getUrl(externalHost, res, automatic);
console.log('***' + authUrl);

res.render('pages/index', { name: "-", tokenState: "OK", momentprj: "-"}); // funziona in locale
})

.get('/testAuthSep', async (req, res) => {

const externalHost = false;
console.log('process.env:' + process.env.port);


// no localhost
const automatic = false;
const authUrl = await authorize_getUrl(externalHost, res, automatic);
console.log('***' + authUrl);


res.redirect(authUrl);
/*
(async () => {
const browser = await launch({headless: false});
const page = await browser.newPage();
await page.goto(authUrl);
//await browser.close();
})();
*/

//res.render('pages/index', { name: authUrl });
//res.redirect(authUrl);
})

/*
.get('/create', async (req, res) => {

console.log('clicked');

scriptId = await createGoogleProject("fromget");

console.log(scriptId);

res.render('pages/index', { name: scriptId, tokenState: "OK" });
})
*/

.post('/createPrj', async(req,res) => {
var prjName = req.body.ProjectName;
scriptId = await createGoogleProject(prjName);

console.log(scriptId);

res.render('pages/index', { name: scriptId, tokenState: "OK", momentprj: "no"});
})

.get('/testGetToken', async (req, res) => {

var tok = req.query.AuthCode;
console.log("test:" + tok);
})

.post('/add', async(req,res) => {
var authCode = req.body.AuthCode;
console.log("post:" + authCode);

const globalOauth2ClientOptions = {

clientId: '1072944905499-vm2v2i5dvn0a0d2o4ca36i1vge8cvbn0.apps.googleusercontent.com',
clientSecret: 'v6V3fKV_zWU7iw1DrpO1rknX',
redirectUri: 'https://hello-clasp.herokuapp.com/testAuth'
};
const oAuth2ClientAuthUrlOptions = { access_type: 'offline', defaultScopes };

var token = convertAuthCodeInToken(authCode, globalOauth2ClientOptions, oAuth2ClientAuthUrlOptions);
console.log("token:" + token);
res.render('pages/index', { name: "-", tokenState: "OK", momentprj: "-" });

})

.get('/testOpen', async (req, res) => {
//res.redirect("http://www.facebook.com") // test
//open("http://www.amazon.com");

(async () => {
const browser = await launch({headless: false});
const page = await browser.newPage();
await page.goto("http://www.amazon.com");
//await browser.close();
})();
})




.get('/addFiles', async (req, res) => {

console.log('adding files');

const config = Conf.get();
console.log(config.projectRootDirectory);

var dirFiles = path.join(__dirname, 'googleFiles');

await saveProject(
//{scriptId, rootDir: config.projectRootDirectory, parentId: parentId ? [parentId] : undefined},
{scriptId, rootDir: dirFiles},
false
);

await pushFiles();

res.render('pages/index', { name: scriptId, tokenState: "OK" });
})


.listen(port, () => console.log('port' + port))

console.log(__dirname);
console.log(path.join(__dirname, 'views'))

Loading