python -> node.js
This commit is contained in:
parent
092f2ec0f3
commit
395fba645d
62 changed files with 726 additions and 1702 deletions
|
|
@ -1,19 +1,15 @@
|
|||
import { Storage } from "@google-cloud/storage";
|
||||
import zlib from "zlib";
|
||||
|
||||
const csClient = new Storage({
|
||||
projectId: 'datacom-poc',
|
||||
}
|
||||
);
|
||||
const BUCKET_NAME = "meeting-report-data";
|
||||
const csClient = new Storage({projectId: process.env.PROJECT_ID});
|
||||
const BUCKET_NAME = process.env.CLOUD_STORAGE_BUCKET_NAME || '';
|
||||
const bucket = csClient.bucket(BUCKET_NAME);
|
||||
|
||||
export const storageController = {
|
||||
saveToGCS: async(folder: string, filename: string, text: string) => {
|
||||
const gzipped = zlib.gzipSync(text);
|
||||
const file = bucket.file((`${folder}/${filename}.json.gz`));
|
||||
await file.save(gzipped, {
|
||||
contentType: 'application/gzip',
|
||||
saveToGCS: async(folder: string, filename: string, content: any, contentType: string) => {
|
||||
const file = bucket.file((`${folder}/${filename}`));
|
||||
await file.save(content, {
|
||||
contentType: contentType,
|
||||
})
|
||||
},
|
||||
loadFromGCS: async(folder: string, filename: string): Promise<string | null> => {
|
||||
|
|
@ -26,6 +22,16 @@ export const storageController = {
|
|||
return null;
|
||||
}
|
||||
},
|
||||
loadJsonFromGCS: async(folder: string, filename: string): Promise<string | null> => {
|
||||
const file = bucket.file(`${folder}/${filename}`);
|
||||
// console.log("loading file:", file.name);
|
||||
try {
|
||||
const [data] = await file.download();
|
||||
return data.toString("utf-8");
|
||||
} catch (err: any) {
|
||||
return null;
|
||||
}
|
||||
},
|
||||
existsInGCS: async(folder: string, filename: string): Promise<boolean> => {
|
||||
const file = bucket.file((`${folder}/${filename}`));
|
||||
console.log("checking file:", file.name);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue