10000 Added thumbnail caching by sbs20 · Pull Request #635 · sbs20/scanservjs · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Added thumbnail caching #635

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ dist
**/server/config/devices.json
**/server/data/output/*
**/server/data/temp/*
**/server/data/thumbnail/*
**/server/data/preview/*.tif
**/scan*.jpg
**/config.local.js
Expand Down
13 changes: 12 additions & 1 deletion packages/server/src/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ module.exports = new class Api {
*/
fileDelete(name) {
log.trace('fileDelete()');
const thumbnail = FileInfo.unsafe(config.thumbnailDirectory, name);
if (thumbnail.exists()) {
thumbnail.delete();
}
const file = FileInfo.unsafe(config.outputDirectory, name);
return file.delete();
}
Expand Down Expand Up @@ -127,7 +131,14 @@ module.exports = new class Api {
async readThumbnail(name) {
const source = FileInfo.unsafe(config.outputDirectory, name);
if (source.extension !== '.zip') {
return await Process.spawn(`convert '${source.fullname}'[0] -resize 256 -quality 75 jpg:-`);
const thumbnail = FileInfo.unsafe(config.thumbnailDirectory, name);
if (thumbnail.exists()) {
return thumbnail.toBuffer();
} else {
const buffer = await Process.spawn(`convert '${source.fullname}'[0] -resize 256 -quality 75 jpg:-`);
thumbnail.save(buffer);
return buffer;
}
}
return [];
}
Expand Down
1 change: 1 addition & 0 deletions packages/server/src/classes/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ module.exports = class Config {

devicesPath: './config/devices.json',
outputDirectory: 'data/output',
thumbnailDirectory: 'data/thumbnail',
previewDirectory: 'data/preview',
tempDirectory: 'data/temp',

Expand Down
6 changes: 6 additions & 0 deletions packages/server/src/configure.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,15 @@ function initialize(rootPath) {
Object.assign(config, {
devicesPath: rootPath + config.devicesPath,
outputDirectory: rootPath + config.outputDirectory,
thumbnailDirectory: rootPath + config.thumbnailDirectory,
previewDirectory: rootPath + config.previewDirectory,
tempDirectory: rootPath + config.tempDirectory
});
}

try {
fs.mkdirSync(config.outputDirectory, { recursive: true });
fs.mkdirSync(config.thumbnailDirectory, { recursive: true });
fs.mkdirSync(config.tempDirectory, { recursive: true });
} catch (exception) {
log.warn(`Error ensuring output and temp directories exist: ${exception}`);
Expand Down Expand Up @@ -204,6 +206,10 @@ function configure(app, rootPath) {
const newName = req.body.newName;
await FileInfo.unsafe(config.outputDirectory, name)
.rename(newName);
const thumbnail = FileInfo.unsafe(config.thumbnailDirectory, name);
if (thumbnail.exists()) {
thumbnail.rename(newName);
}
res.send('200');
} catch (error) {
sendError(res, 500, error);
Expand Down
1 change: 1 addition & 0 deletions packages/server/src/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
* @property {string} tesseract
* @property {string} devicesPath
* @property {string} outputDirectory
* @property {string} thumbnailDirectory
* @property {string} previewDirectory
* @property {string} tempDirectory
* @property {number} previewResolution
Expand Down
0