koishi-plugin-chatluna-storage-service 0.0.10 → 0.0.11
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.
- package/lib/index.cjs +9 -9
- package/lib/index.mjs +9 -9
- package/lib/types.d.ts +2 -2
- package/package.json +1 -1
package/lib/index.cjs
CHANGED
|
@@ -144,9 +144,9 @@ var ChatLunaStorageService = class extends import_koishi.Service {
|
|
|
144
144
|
type: "string",
|
|
145
145
|
nullable: true
|
|
146
146
|
},
|
|
147
|
-
expireTime: "
|
|
147
|
+
expireTime: "timestamp",
|
|
148
148
|
size: "integer",
|
|
149
|
-
accessTime: "
|
|
149
|
+
accessTime: "timestamp",
|
|
150
150
|
accessCount: "integer"
|
|
151
151
|
},
|
|
152
152
|
{
|
|
@@ -170,7 +170,7 @@ var ChatLunaStorageService = class extends import_koishi.Service {
|
|
|
170
170
|
backendPath;
|
|
171
171
|
async initializeLRU() {
|
|
172
172
|
const files = await this.ctx.database.get("chatluna_storage_temp", {});
|
|
173
|
-
files.sort((a, b) => b.accessTime - a.accessTime);
|
|
173
|
+
files.sort((a, b) => b.accessTime.getTime() - a.accessTime.getTime());
|
|
174
174
|
for (const file of files) {
|
|
175
175
|
this.addToLRU(file.id);
|
|
176
176
|
}
|
|
@@ -206,7 +206,7 @@ var ChatLunaStorageService = class extends import_koishi.Service {
|
|
|
206
206
|
const totalSize = files.reduce((sum, file) => sum + file.size, 0);
|
|
207
207
|
const maxSizeBytes = this.config.maxStorageSize * 1024 * 1024;
|
|
208
208
|
if (totalSize <= maxSizeBytes) return;
|
|
209
|
-
const sortedFiles = files.sort((a, b) => a.accessTime - b.accessTime);
|
|
209
|
+
const sortedFiles = files.sort((a, b) => a.accessTime.getTime() - b.accessTime.getTime());
|
|
210
210
|
let currentSize = totalSize;
|
|
211
211
|
for (const file of sortedFiles) {
|
|
212
212
|
if (currentSize <= maxSizeBytes * 0.8) break;
|
|
@@ -229,7 +229,7 @@ var ChatLunaStorageService = class extends import_koishi.Service {
|
|
|
229
229
|
async cleanupByFileCount() {
|
|
230
230
|
const files = await this.ctx.database.get("chatluna_storage_temp", {});
|
|
231
231
|
if (files.length <= this.config.maxStorageCount) return;
|
|
232
|
-
const sortedFiles = files.sort((a, b) => a.accessTime - b.accessTime);
|
|
232
|
+
const sortedFiles = files.sort((a, b) => a.accessTime.getTime() - b.accessTime.getTime());
|
|
233
233
|
const filesToDelete = files.length - Math.floor(this.config.maxStorageCount * 0.8);
|
|
234
234
|
for (let i = 0; i < filesToDelete; i++) {
|
|
235
235
|
const file = sortedFiles[i];
|
|
@@ -257,7 +257,7 @@ var ChatLunaStorageService = class extends import_koishi.Service {
|
|
|
257
257
|
"chatluna_storage_temp",
|
|
258
258
|
{
|
|
259
259
|
expireTime: {
|
|
260
|
-
$lt: Date.now()
|
|
260
|
+
$lt: new Date(Date.now())
|
|
261
261
|
}
|
|
262
262
|
}
|
|
263
263
|
);
|
|
@@ -310,8 +310,8 @@ var ChatLunaStorageService = class extends import_koishi.Service {
|
|
|
310
310
|
recursive: true
|
|
311
311
|
});
|
|
312
312
|
await import_promises.default.writeFile(filePath, processedBuffer);
|
|
313
|
-
const expireTime = Date.now() + (expireHours || this.config.tempCacheTime) * 60 * 60 * 1e3;
|
|
314
|
-
const currentTime = Date
|
|
313
|
+
const expireTime = new Date(Date.now() + (expireHours || this.config.tempCacheTime) * 60 * 60 * 1e3);
|
|
314
|
+
const currentTime = /* @__PURE__ */ new Date();
|
|
315
315
|
const fileInfo = {
|
|
316
316
|
id: randomName.split(".")[0],
|
|
317
317
|
path: filePath,
|
|
@@ -341,7 +341,7 @@ var ChatLunaStorageService = class extends import_koishi.Service {
|
|
|
341
341
|
}
|
|
342
342
|
if (fileInfo.length === 0) return null;
|
|
343
343
|
const file = fileInfo[0];
|
|
344
|
-
const currentTime = Date
|
|
344
|
+
const currentTime = /* @__PURE__ */ new Date();
|
|
345
345
|
await this.ctx.database.set(
|
|
346
346
|
"chatluna_storage_temp",
|
|
347
347
|
{ id: file.id },
|
package/lib/index.mjs
CHANGED
|
@@ -107,9 +107,9 @@ var ChatLunaStorageService = class extends Service {
|
|
|
107
107
|
type: "string",
|
|
108
108
|
nullable: true
|
|
109
109
|
},
|
|
110
|
-
expireTime: "
|
|
110
|
+
expireTime: "timestamp",
|
|
111
111
|
size: "integer",
|
|
112
|
-
accessTime: "
|
|
112
|
+
accessTime: "timestamp",
|
|
113
113
|
accessCount: "integer"
|
|
114
114
|
},
|
|
115
115
|
{
|
|
@@ -133,7 +133,7 @@ var ChatLunaStorageService = class extends Service {
|
|
|
133
133
|
backendPath;
|
|
134
134
|
async initializeLRU() {
|
|
135
135
|
const files = await this.ctx.database.get("chatluna_storage_temp", {});
|
|
136
|
-
files.sort((a, b) => b.accessTime - a.accessTime);
|
|
136
|
+
files.sort((a, b) => b.accessTime.getTime() - a.accessTime.getTime());
|
|
137
137
|
for (const file of files) {
|
|
138
138
|
this.addToLRU(file.id);
|
|
139
139
|
}
|
|
@@ -169,7 +169,7 @@ var ChatLunaStorageService = class extends Service {
|
|
|
169
169
|
const totalSize = files.reduce((sum, file) => sum + file.size, 0);
|
|
170
170
|
const maxSizeBytes = this.config.maxStorageSize * 1024 * 1024;
|
|
171
171
|
if (totalSize <= maxSizeBytes) return;
|
|
172
|
-
const sortedFiles = files.sort((a, b) => a.accessTime - b.accessTime);
|
|
172
|
+
const sortedFiles = files.sort((a, b) => a.accessTime.getTime() - b.accessTime.getTime());
|
|
173
173
|
let currentSize = totalSize;
|
|
174
174
|
for (const file of sortedFiles) {
|
|
175
175
|
if (currentSize <= maxSizeBytes * 0.8) break;
|
|
@@ -192,7 +192,7 @@ var ChatLunaStorageService = class extends Service {
|
|
|
192
192
|
async cleanupByFileCount() {
|
|
193
193
|
const files = await this.ctx.database.get("chatluna_storage_temp", {});
|
|
194
194
|
if (files.length <= this.config.maxStorageCount) return;
|
|
195
|
-
const sortedFiles = files.sort((a, b) => a.accessTime - b.accessTime);
|
|
195
|
+
const sortedFiles = files.sort((a, b) => a.accessTime.getTime() - b.accessTime.getTime());
|
|
196
196
|
const filesToDelete = files.length - Math.floor(this.config.maxStorageCount * 0.8);
|
|
197
197
|
for (let i = 0; i < filesToDelete; i++) {
|
|
198
198
|
const file = sortedFiles[i];
|
|
@@ -220,7 +220,7 @@ var ChatLunaStorageService = class extends Service {
|
|
|
220
220
|
"chatluna_storage_temp",
|
|
221
221
|
{
|
|
222
222
|
expireTime: {
|
|
223
|
-
$lt: Date.now()
|
|
223
|
+
$lt: new Date(Date.now())
|
|
224
224
|
}
|
|
225
225
|
}
|
|
226
226
|
);
|
|
@@ -273,8 +273,8 @@ var ChatLunaStorageService = class extends Service {
|
|
|
273
273
|
recursive: true
|
|
274
274
|
});
|
|
275
275
|
await fs.writeFile(filePath, processedBuffer);
|
|
276
|
-
const expireTime = Date.now() + (expireHours || this.config.tempCacheTime) * 60 * 60 * 1e3;
|
|
277
|
-
const currentTime = Date
|
|
276
|
+
const expireTime = new Date(Date.now() + (expireHours || this.config.tempCacheTime) * 60 * 60 * 1e3);
|
|
277
|
+
const currentTime = /* @__PURE__ */ new Date();
|
|
278
278
|
const fileInfo = {
|
|
279
279
|
id: randomName.split(".")[0],
|
|
280
280
|
path: filePath,
|
|
@@ -304,7 +304,7 @@ var ChatLunaStorageService = class extends Service {
|
|
|
304
304
|
}
|
|
305
305
|
if (fileInfo.length === 0) return null;
|
|
306
306
|
const file = fileInfo[0];
|
|
307
|
-
const currentTime = Date
|
|
307
|
+
const currentTime = /* @__PURE__ */ new Date();
|
|
308
308
|
await this.ctx.database.set(
|
|
309
309
|
"chatluna_storage_temp",
|
|
310
310
|
{ id: file.id },
|
package/lib/types.d.ts
CHANGED
|
@@ -2,10 +2,10 @@ export interface TempFileInfo {
|
|
|
2
2
|
path: string;
|
|
3
3
|
name: string;
|
|
4
4
|
type?: string;
|
|
5
|
-
expireTime:
|
|
5
|
+
expireTime: Date;
|
|
6
6
|
id: string;
|
|
7
7
|
size: number;
|
|
8
|
-
accessTime:
|
|
8
|
+
accessTime: Date;
|
|
9
9
|
accessCount: number;
|
|
10
10
|
}
|
|
11
11
|
export interface TempFileInfoWithData<T> extends TempFileInfo {
|