Move to src folder

This commit is contained in:
Daniel Kluge 2022-05-07 16:11:22 +02:00
parent 0fc999a019
commit 1a646d1dff
2 changed files with 8 additions and 17 deletions

View File

@ -2,10 +2,10 @@
"name": "google-photo-album-sync", "name": "google-photo-album-sync",
"version": "1.0.0", "version": "1.0.0",
"description": "Syncs a google photo album with a harddrive", "description": "Syncs a google photo album with a harddrive",
"main": "index.js", "main": "src/sync.js",
"type": "module", "type": "module",
"scripts": { "scripts": {
"token": "node getToken.js", "token": "node src/getToken.js",
"test": "echo \"Error: no test specified\" && exit 1" "test": "echo \"Error: no test specified\" && exit 1"
}, },
"keywords": [ "keywords": [

View File

@ -2,7 +2,9 @@ import express from "express";
import bodyParser from "body-parser"; import bodyParser from "body-parser";
import open from "open"; import open from "open";
import fetch from "node-fetch"; import fetch from "node-fetch";
import {readFileSync, writeFileSync} from "fs" import {readFileSync, writeFileSync} from "fs";
import {dirname} from "path";
import {fileURLToPath} from "url";
const app = express() const app = express()
app.use(bodyParser.urlencoded({ extended: true })); app.use(bodyParser.urlencoded({ extended: true }));
@ -11,8 +13,8 @@ const port = 8080;
let state = "code"; let state = "code";
// Read and parse JSON // Read and parse JSON. There is no __dirname for modules
const secrets = JSON.parse(readFileSync("./secrets.json", "utf8")); const secrets = JSON.parse(readFileSync(`${dirname(fileURLToPath(import.meta.url))}/../secrets.json`, "utf8"));
// Express route that prints request body and query parameters // Express route that prints request body and query parameters
app.use("/", (req, res) => { app.use("/", (req, res) => {
@ -20,7 +22,7 @@ app.use("/", (req, res) => {
case "code": { case "code": {
state = "token"; state = "token";
getToken(req.query); getToken(req.query);
res.status(200).json(req.query).end(); res.status(200).send("Done! You can close this window.").end();
break; break;
} }
case "token": { case "token": {
@ -32,17 +34,6 @@ app.use("/", (req, res) => {
} }
}); });
app.use("/token", (req, res) => {
console.log({
get: req.query,
post: req.body
});
res.status(200).json({
get: req.query,
post: req.body
}).end()
});
const server = app.listen(port, () => console.log(`Example app listening on port ${port}!`)); const server = app.listen(port, () => console.log(`Example app listening on port ${port}!`));
const token = "miau"; const token = "miau";