Skip to content

Commit 645cf61

Browse files
committed
feat: create index file if it doesn't exist
1 parent 4fb8508 commit 645cf61

3 files changed

Lines changed: 7 additions & 4 deletions

File tree

src/bucket/bucketModule.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ const bucket = new Bucket(
1717
imageBucket.namespace,
1818
imageBucket.name,
1919
);
20-
const index = new FileIndex(imageBucket.index.file_path);
20+
const index = new FileIndex(imageBucket.index.filePath);
2121
const imageBucketService = new ImageBucketService(bucket, index);
2222

2323
export const bucketModule = {

src/common/config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ export const appConfig = () => ({
4040
namespace: process.env.IMAGE_BUCKET_NAMESPACE || 'aaaaa',
4141
name: process.env.IMAGE_BUCKET_NAME || 'some-bucket-name',
4242
index: {
43-
file_path: process.env.IMAGE_INDEX_FILE_PATH || './tmp/index.txt',
43+
filePath: process.env.IMAGE_INDEX_FILE_PATH || './tmp/index.txt',
4444
},
4545
},
4646
post: {

src/index/fileIndex.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
import type { IIndex } from '@index/types';
2-
import { createReadStream } from 'fs';
2+
import { createReadStream, appendFileSync } from 'fs';
33
import { appendFile } from 'fs/promises';
44
import split2 from 'split2';
55
import { Transform } from 'stream';
66
import { pipeline } from 'stream/promises';
77

88
export class FileIndex implements IIndex {
9-
constructor(private filePath: string) {}
9+
constructor(private filePath: string) {
10+
// Create file if it doesn't exist
11+
appendFileSync(this.filePath, '');
12+
}
1013

1114
async get(key: string): Promise<string | null> {
1215
let indexValue = null;

0 commit comments

Comments
 (0)