@adminforth/storage-adapter-local 1.0.2 → 1.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/dist/index.js +16 -2
  2. package/index.ts +15 -3
  3. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -15,6 +15,9 @@ import { Level } from 'level';
15
15
  class AdminForthStorageAdapterLocalFilesystem {
16
16
  constructor(options) {
17
17
  this.options = options;
18
+ if (!this.options.mode) {
19
+ this.options.mode = "private";
20
+ }
18
21
  }
19
22
  presignUrl(urlPath, expiresIn, payload = {}) {
20
23
  const expires = Math.floor(Date.now() / 1000) + expiresIn;
@@ -69,13 +72,24 @@ class AdminForthStorageAdapterLocalFilesystem {
69
72
  });
70
73
  }
71
74
  markKeyForDeletation(key) {
75
+ return __awaiter(this, void 0, void 0, function* () {
76
+ throw new Error("Method \"markKeyForDeletation\" is deprecated, use markKeyForDeletion instead");
77
+ });
78
+ }
79
+ markKeyForNotDeletation(key) {
80
+ return __awaiter(this, void 0, void 0, function* () {
81
+ throw new Error("Method \"markKeyForNotDeletation\" is deprecated, use markKeyForNotDeletion instead");
82
+ });
83
+ }
84
+ markKeyForDeletion(key) {
72
85
  return __awaiter(this, void 0, void 0, function* () {
73
86
  const metadata = yield this.metadataDb.get(key).catch((e) => {
74
87
  console.error(`Could not read metadata from db: ${e}`);
75
88
  throw new Error(`Could not read metadata from db: ${e}`);
76
89
  });
77
90
  if (!metadata) {
78
- throw new Error(`Metadata for key ${key} not found`);
91
+ console.error(`Metadata for key ${key} not found`);
92
+ return;
79
93
  }
80
94
  const metadataParsed = JSON.parse(metadata);
81
95
  try {
@@ -101,7 +115,7 @@ class AdminForthStorageAdapterLocalFilesystem {
101
115
  * This method should work even if the file does not exist yet (e.g. only presigned URL was generated).
102
116
  * @param key - The key of the file to be uploaded e.g. "uploads/file.txt"
103
117
  */
104
- markKeyForNotDeletation(key) {
118
+ markKeyForNotDeletion(key) {
105
119
  return __awaiter(this, void 0, void 0, function* () {
106
120
  try {
107
121
  // if key exists, delete it
package/index.ts CHANGED
@@ -12,7 +12,7 @@ declare global {
12
12
 
13
13
  interface StorageLocalFilesystemOptions {
14
14
  fileSystemFolder: string; // folder where files will be stored
15
- mode: "public" | "private"; // public if all files should be accessible from the web, private only if could be accessed by temporary presigned links
15
+ mode?: "public" | "private"; // public if all files should be accessible from the web, private only if could be accessed by temporary presigned links
16
16
  signingSecret: string; // secret used to generate presigned URLs
17
17
  adminServeBaseUrl?: string; // base URL for serving files e.g. static/uploads. If not defined will be generated automatically
18
18
  // please note that is adminforth base URL is set, files will be available on `${adminforth.config.baseUrl}/${adminServeBaseUrl}/{key}`
@@ -30,6 +30,9 @@ export default class AdminForthStorageAdapterLocalFilesystem implements StorageA
30
30
 
31
31
  constructor(options: StorageLocalFilesystemOptions) {
32
32
  this.options = options;
33
+ if (!this.options.mode) {
34
+ this.options.mode = "private";
35
+ }
33
36
  }
34
37
 
35
38
  presignUrl(urlPath: string, expiresIn: number, payload: Record<string, string> = {}): string {
@@ -96,12 +99,21 @@ export default class AdminForthStorageAdapterLocalFilesystem implements StorageA
96
99
  }
97
100
 
98
101
  async markKeyForDeletation(key: string): Promise<void> {
102
+ throw new Error("Method \"markKeyForDeletation\" is deprecated, use markKeyForDeletion instead");
103
+ }
104
+
105
+ async markKeyForNotDeletation(key: string): Promise<void> {
106
+ throw new Error("Method \"markKeyForNotDeletation\" is deprecated, use markKeyForNotDeletion instead");
107
+ }
108
+
109
+ async markKeyForDeletion(key: string): Promise<void> {
99
110
  const metadata = await this.metadataDb.get(key).catch((e) => {
100
111
  console.error(`Could not read metadata from db: ${e}`);
101
112
  throw new Error(`Could not read metadata from db: ${e}`);
102
113
  });
103
114
  if (!metadata) {
104
- throw new Error(`Metadata for key ${key} not found`);
115
+ console.error(`Metadata for key ${key} not found`);
116
+ return;
105
117
  }
106
118
  const metadataParsed = JSON.parse(metadata);
107
119
 
@@ -126,7 +138,7 @@ export default class AdminForthStorageAdapterLocalFilesystem implements StorageA
126
138
  * This method should work even if the file does not exist yet (e.g. only presigned URL was generated).
127
139
  * @param key - The key of the file to be uploaded e.g. "uploads/file.txt"
128
140
  */
129
- async markKeyForNotDeletation(key: string): Promise<void> {
141
+ async markKeyForNotDeletion(key: string): Promise<void> {
130
142
  try {
131
143
  // if key exists, delete it
132
144
  await this.candidatesForDeletionDb.del(key);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adminforth/storage-adapter-local",
3
- "version": "1.0.2",
3
+ "version": "1.0.4",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "type": "module",