-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
45 lines (38 loc) · 1.36 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import path from "path";
import mime from "mime";
import { uploadFile } from "./uploadFile.js";
import getToken from "./getToken.js";
import { notionCreateGCPFile } from "./notionCreateGCPFile.js";
import readline from "readline";
// Replace the following variables with your own values
const bucketName = "guestwhat-public";
// const folderName = "Test";
// const filePath = "/Users/axel/Downloads/Penguin-3970-Edit.jpg";
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout,
});
rl.question("Enter the file path: ", (filePath) => {
rl.question("Enter the folder name: ", (folderName) => {
// Close the readline interface after getting inputs
rl.close();
// Call the function with the provided filePath and folderName
runFunctions(filePath, folderName);
});
});
// Call the upload function
async function runFunctions(filePath, folderName) {
const fileName = path.basename(filePath);
const objectName = `${folderName}/${fileName}`;
const contentType = mime.getType(filePath) || "application/octet-stream";
getToken()
.then((accessToken) => {
uploadFile(bucketName, objectName, filePath, contentType, accessToken).then((uploadedFileDetails) => {
console.log(uploadedFileDetails);
notionCreateGCPFile(uploadedFileDetails);
});
})
.catch((error) => {
// Handle error
});
}