-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
196 additions
and
65 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 |
---|---|---|
@@ -1,16 +1,18 @@ | ||
/node_modules/ | ||
/storage/collections/*.json | ||
/storage/collections/ | ||
/storage/database/*.db | ||
/storage/user_files/* | ||
/storage/temp_files/* | ||
/storage/job_files/* | ||
/storage/service_files/* | ||
/storage/user_files/ | ||
/storage/temp_files/ | ||
/storage/job_files/ | ||
/storage/service_files/ | ||
/storage/item_thumb_cache/ | ||
/nbproject/ | ||
/package-lock.json | ||
/.node-xmlhttprequest-sync-* | ||
/privatekey.json | ||
coverage/ | ||
/test-report.html | ||
/logs | ||
.idea | ||
/config_server.json | ||
.idea | ||
.vscode |
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
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
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
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
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
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,51 @@ | ||
import DB from '../utils/db.js'; | ||
import fse from 'fs-extra'; | ||
import path from 'path'; | ||
|
||
export default class ItemStore { | ||
|
||
constructor() { | ||
this.thumbCacheFolder = './storage/item_thumb_cache'; | ||
this.db = DB.load('item_cache'); | ||
} | ||
|
||
database() { | ||
return this.db; | ||
} | ||
|
||
async clear() { | ||
await fse.ensureDir(this.thumbCacheFolder); | ||
await this.removeOutdated(); | ||
} | ||
|
||
async getItem(id) { | ||
return await this.db.findOneAsync({_id: id}); | ||
} | ||
|
||
async removeOutdated() { | ||
// 7 day cache | ||
const daysAgo = Date.now() - 1000 * 60 * 60 * 24 * 7; | ||
return await this.db.removeAsync({ | ||
_time: {$lt: daysAgo} | ||
}, { | ||
multi: true | ||
}); | ||
} | ||
|
||
async addItem(data) { | ||
const dbData = Object.assign({ | ||
_id: data.id, | ||
_time: Date.now() | ||
}, data); | ||
return await this.db.updateAsync(dbData, { upsert: true }); | ||
} | ||
|
||
getThumbPath(id) { | ||
return path.join(this.thumbCacheFolder, `${id}.png`); | ||
} | ||
|
||
async hasThumb(id) { | ||
return await fse.pathExists(this.getThumbPath(id)); | ||
} | ||
|
||
} |
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
Oops, something went wrong.