@adminforth/storage-adapter-local 1.0.3 → 1.0.5

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 +44 -2
  2. package/index.ts +40 -2
  3. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -73,12 +73,54 @@ class AdminForthStorageAdapterLocalFilesystem {
73
73
  }
74
74
  markKeyForDeletation(key) {
75
75
  return __awaiter(this, void 0, void 0, function* () {
76
+ console.error("Method \"markKeyForDeletation\" is deprecated, use markKeyForDeletion instead");
76
77
  const metadata = yield this.metadataDb.get(key).catch((e) => {
77
78
  console.error(`Could not read metadata from db: ${e}`);
78
79
  throw new Error(`Could not read metadata from db: ${e}`);
79
80
  });
80
81
  if (!metadata) {
81
- throw new Error(`Metadata for key ${key} not found`);
82
+ console.error(`Metadata for key ${key} not found`);
83
+ return;
84
+ }
85
+ const metadataParsed = JSON.parse(metadata);
86
+ try {
87
+ yield this.candidatesForDeletionDb.get(key);
88
+ // if key already exists, do nothing
89
+ return;
90
+ }
91
+ catch (e) {
92
+ // if key does not exist, continue
93
+ }
94
+ try {
95
+ yield this.candidatesForDeletionDb.put(key, metadataParsed.createdAt);
96
+ }
97
+ catch (e) {
98
+ console.error(`Could not write metadata to db: ${e}`);
99
+ throw new Error(`Could not write metadata to db: ${e}`);
100
+ }
101
+ });
102
+ }
103
+ markKeyForNotDeletation(key) {
104
+ return __awaiter(this, void 0, void 0, function* () {
105
+ console.error("Method \"markKeyForNotDeletation\" is deprecated, use markKeyForNotDeletion instead");
106
+ try {
107
+ // if key exists, delete it
108
+ yield this.candidatesForDeletionDb.del(key);
109
+ }
110
+ catch (e) {
111
+ // if key does not exist, do nothing
112
+ }
113
+ });
114
+ }
115
+ markKeyForDeletion(key) {
116
+ return __awaiter(this, void 0, void 0, function* () {
117
+ const metadata = yield this.metadataDb.get(key).catch((e) => {
118
+ console.error(`Could not read metadata from db: ${e}`);
119
+ throw new Error(`Could not read metadata from db: ${e}`);
120
+ });
121
+ if (!metadata) {
122
+ console.error(`Metadata for key ${key} not found`);
123
+ return;
82
124
  }
83
125
  const metadataParsed = JSON.parse(metadata);
84
126
  try {
@@ -104,7 +146,7 @@ class AdminForthStorageAdapterLocalFilesystem {
104
146
  * This method should work even if the file does not exist yet (e.g. only presigned URL was generated).
105
147
  * @param key - The key of the file to be uploaded e.g. "uploads/file.txt"
106
148
  */
107
- markKeyForNotDeletation(key) {
149
+ markKeyForNotDeletion(key) {
108
150
  return __awaiter(this, void 0, void 0, function* () {
109
151
  try {
110
152
  // if key exists, delete it
package/index.ts CHANGED
@@ -99,12 +99,50 @@ export default class AdminForthStorageAdapterLocalFilesystem implements StorageA
99
99
  }
100
100
 
101
101
  async markKeyForDeletation(key: string): Promise<void> {
102
+ console.error("Method \"markKeyForDeletation\" is deprecated, use markKeyForDeletion instead");
102
103
  const metadata = await this.metadataDb.get(key).catch((e) => {
103
104
  console.error(`Could not read metadata from db: ${e}`);
104
105
  throw new Error(`Could not read metadata from db: ${e}`);
105
106
  });
106
107
  if (!metadata) {
107
- throw new Error(`Metadata for key ${key} not found`);
108
+ console.error(`Metadata for key ${key} not found`);
109
+ return;
110
+ }
111
+ const metadataParsed = JSON.parse(metadata);
112
+
113
+ try {
114
+ await this.candidatesForDeletionDb.get(key);
115
+ // if key already exists, do nothing
116
+ return;
117
+ } catch (e) {
118
+ // if key does not exist, continue
119
+ }
120
+ try {
121
+ await this.candidatesForDeletionDb.put(key, metadataParsed.createdAt)
122
+ } catch (e) {
123
+ console.error(`Could not write metadata to db: ${e}`);
124
+ throw new Error(`Could not write metadata to db: ${e}`);
125
+ }
126
+ }
127
+
128
+ async markKeyForNotDeletation(key: string): Promise<void> {
129
+ console.error("Method \"markKeyForNotDeletation\" is deprecated, use markKeyForNotDeletion instead");
130
+ try {
131
+ // if key exists, delete it
132
+ await this.candidatesForDeletionDb.del(key);
133
+ } catch (e) {
134
+ // if key does not exist, do nothing
135
+ }
136
+ }
137
+
138
+ async markKeyForDeletion(key: string): Promise<void> {
139
+ const metadata = await this.metadataDb.get(key).catch((e) => {
140
+ console.error(`Could not read metadata from db: ${e}`);
141
+ throw new Error(`Could not read metadata from db: ${e}`);
142
+ });
143
+ if (!metadata) {
144
+ console.error(`Metadata for key ${key} not found`);
145
+ return;
108
146
  }
109
147
  const metadataParsed = JSON.parse(metadata);
110
148
 
@@ -129,7 +167,7 @@ export default class AdminForthStorageAdapterLocalFilesystem implements StorageA
129
167
  * This method should work even if the file does not exist yet (e.g. only presigned URL was generated).
130
168
  * @param key - The key of the file to be uploaded e.g. "uploads/file.txt"
131
169
  */
132
- async markKeyForNotDeletation(key: string): Promise<void> {
170
+ async markKeyForNotDeletion(key: string): Promise<void> {
133
171
  try {
134
172
  // if key exists, delete it
135
173
  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.3",
3
+ "version": "1.0.5",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "type": "module",