-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from sarthakpranesh/switchToLocalStore
chore: adding mocked S3 bucket for local filestore
- Loading branch information
Showing
6 changed files
with
86 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# port you want the server to use, defaults to 8080 | ||
SERVER_PORT=8001 | ||
|
||
# you want to use gcp or local filesystem | ||
# gcp -> google cloud storage, local -> local filesystem | ||
# defaults to gcp | ||
STORAGE_TYPE=local | ||
|
||
# if storage type is gcp/not set, then uncomment below and add the bucket name | ||
# defaults to "athene-diagram-files" | ||
# STORAGE_GCP_BUCKET_NAME=athene-diagram-files |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,4 +2,7 @@ | |
node_modules | ||
|
||
# Output files | ||
dist | ||
dist | ||
|
||
# local filestore | ||
localFileStore |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
|
||
import EventEmitter from 'node:events'; | ||
import * as fs from 'node:fs'; | ||
|
||
export default (() => { | ||
const base = './localFileStore/' | ||
const metaPath = `${base}_meta.json` | ||
if (fs.existsSync(base) === false) { | ||
fs.mkdirSync(base) | ||
} | ||
if (fs.existsSync(metaPath) === false) { | ||
fs.writeFileSync(metaPath, JSON.stringify({})) | ||
} | ||
return { | ||
file: (filePath: string) => { | ||
const fullPath = `${base}${filePath}` | ||
return { | ||
exists: () => { | ||
return [fs.existsSync(fullPath)] | ||
}, | ||
download: async () => { | ||
return [new Uint8Array(fs.readFileSync(fullPath))] | ||
}, | ||
createWriteStream: () => { | ||
return fs.createWriteStream(fullPath) | ||
}, | ||
createReadStream: () => { | ||
return fs.createReadStream(fullPath) | ||
}, | ||
save: (fileContent: string, meta?: undefined | any) => { | ||
if (typeof meta === 'object') { | ||
const rawMeta = fs.readFileSync(metaPath); | ||
const _meta = JSON.parse(rawMeta.toString()) | ||
_meta[fullPath] = meta.metadata | ||
fs.writeFileSync(metaPath, JSON.stringify(_meta)) | ||
} | ||
fs.writeFileSync(fullPath, fileContent) | ||
}, | ||
getMetadata: () => { | ||
const rawMeta = fs.readFileSync(metaPath); | ||
const _meta = JSON.parse(rawMeta.toString()) | ||
return [_meta[fullPath]] | ||
} | ||
} | ||
} | ||
} | ||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters