20251125 save
This commit is contained in:
parent
922fa0e77a
commit
092f2ec0f3
11 changed files with 299 additions and 1 deletions
39
functions/generate_minutes/src/logics/storage.ts
Normal file
39
functions/generate_minutes/src/logics/storage.ts
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
import { Storage } from "@google-cloud/storage";
|
||||
import zlib from "zlib";
|
||||
|
||||
const csClient = new Storage({
|
||||
projectId: 'datacom-poc',
|
||||
}
|
||||
);
|
||||
const BUCKET_NAME = "meeting-report-data";
|
||||
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',
|
||||
})
|
||||
},
|
||||
loadFromGCS: 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 zlib.gunzipSync(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);
|
||||
try {
|
||||
const [exist] = await file.exists();
|
||||
return exist;
|
||||
} catch (err: any) {
|
||||
return false;
|
||||
}
|
||||
},
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue