Skip to content

TagSpaces is an offline, open source, document manager with tagging support

Thumbnail generation by upload on S3 in web browser (#1894)

Stanimir6812bf460e14
diff --git a/app/reducers/io-actions.ts b/app/reducers/io-actions.ts
index c2b764515..4ebf6e5cb 100644
--- a/app/reducers/io-actions.ts
+++ b/app/reducers/io-actions.ts
@@ -259,7 +259,7 @@ const actions = {
.then((fsEntry: TS.FileSystemEntry) => {
return generateThumbnailPromise(
PlatformIO.haveObjectStoreSupport() ? url : fsEntry.path,
- 400
+ fsEntry.size
).then(dataURL => {
if (dataURL && dataURL.length > 6) {
const baseString = dataURL.split(',').pop();
@@ -369,6 +369,36 @@ const actions = {
onUploadProgress
);
if (fsEntry) {
+ // Generate Thumbnail
+ const thumbPath = await generateThumbnailPromise(
+ PlatformIO.getURLforPath(fileTargetPath),
+ fsEntry.size
+ )
+ .then(dataURL => {
+ if (dataURL && dataURL.length > 6) {
+ const baseString = dataURL.split(',').pop();
+ const fileContent = base64ToArrayBuffer(baseString);
+ const thumbPath = getThumbFileLocationForFile(
+ fileTargetPath,
+ PlatformIO.getDirSeparator(),
+ false
+ );
+ return PlatformIO.saveBinaryFilePromise(
+ { path: thumbPath },
+ fileContent,
+ true
+ ).then(() => thumbPath);
+ }
+ return undefined;
+ })
+ .catch(err => {
+ console.error('error generateThumbnail:', err);
+ });
+ if (thumbPath) {
+ fsEntry.thumbPath = PlatformIO.getURLforPath(thumbPath);
+ }
+ fsEntries.push(fsEntry);
+
dispatch(
AppActions.showNotification(
'File ' + fileTargetPath + ' successfully imported.',
@@ -376,7 +406,6 @@ const actions = {
true
)
);
- fsEntries.push(fsEntry);
// dispatch(AppActions.reflectCreateEntry(fileTargetPath, true));
}
} catch (error) {
@@ -521,7 +550,7 @@ const actions = {
.catch(err => {
// console.log('Error getting file:' + job[0] + ' ' + err);
if (fileType === 'thumb' && job[3]) {
- return generateThumbnailPromise(job[3], 400).then(dataURL => {
+ return generateThumbnailPromise(job[3], 0).then(dataURL => {
if (dataURL && dataURL.length > 6) {
const baseString = dataURL.split(',').pop();
const fileContent = base64ToArrayBuffer(baseString);
diff --git a/app/services/thumbsgenerator.ts b/app/services/thumbsgenerator.ts
index b8354b58f..082edc4c4 100644
--- a/app/services/thumbsgenerator.ts
+++ b/app/services/thumbsgenerator.ts
@@ -290,7 +290,9 @@ export function generateThumbnailPromise(fileURL: string, fileSize: number) {
PlatformIO.getDirSeparator()
).toLowerCase();
- const fileURLEscaped = encodeFileName(fileURL, PlatformIO.getDirSeparator());
+ const fileURLEscaped = /^https?:\/\//.test(fileURL)
+ ? fileURL
+ : encodeFileName(fileURL, PlatformIO.getDirSeparator());
if (supportedImgs.indexOf(ext) >= 0) {
if (Pro && ext === 'tga') {
diff --git a/package-lock.json b/package-lock.json
index 0af618440..90d5640c1 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -46,7 +46,6 @@
"i18next": "^20.3.5",
"i18next-browser-languagedetector": "^6.1.2",
"i18next-http-backend": "^1.2.8",
- "jszip": "^3.7.1",
"leaflet": "^1.7.1",
"marked": "^4.0.12",
"mgrs": "^1.0.0",
@@ -25021,7 +25020,8 @@
"node_modules/immediate": {
"version": "3.0.6",
"resolved": "https://registry.npmjs.org/immediate/-/immediate-3.0.6.tgz",
- "integrity": "sha512-XXOFtyqDjNDAQxVfYxuF7g9Il/IbWmmlQg2MYKOH8ExIT1qg6xc4zyS3HaEEATgs1btfzxq15ciUiY7gjSXRGQ=="
+ "integrity": "sha512-XXOFtyqDjNDAQxVfYxuF7g9Il/IbWmmlQg2MYKOH8ExIT1qg6xc4zyS3HaEEATgs1btfzxq15ciUiY7gjSXRGQ==",
+ "dev": true
},
"node_modules/immer": {
"version": "9.0.6",
@@ -31022,6 +31022,7 @@
"version": "3.10.1",
"resolved": "https://registry.npmjs.org/jszip/-/jszip-3.10.1.tgz",
"integrity": "sha512-xXDvecyTpGLrqFrvkrUSoxxfJI5AH7U8zxxtVclpsUtMCq4JQ290LY8AW5c7Ggnr/Y/oK+bQMbqK2qmtk3pN4g==",
+ "dev": true,
"dependencies": {
"lie": "~3.3.0",
"pako": "~1.0.2",
@@ -31032,7 +31033,8 @@
"node_modules/jszip/node_modules/pako": {
"version": "1.0.11",
"resolved": "https://registry.npmjs.org/pako/-/pako-1.0.11.tgz",
- "integrity": "sha512-4hLB8Py4zZce5s4yd9XzopqwVv/yGNhV1Bl8NTmCq1763HeK2+EwVTv+leGeL13Dnh2wfbqowVPXCIO0z4taYw=="
+ "integrity": "sha512-4hLB8Py4zZce5s4yd9XzopqwVv/yGNhV1Bl8NTmCq1763HeK2+EwVTv+leGeL13Dnh2wfbqowVPXCIO0z4taYw==",
+ "dev": true
},
"node_modules/just-extend": {
"version": "4.2.1",
@@ -31321,6 +31323,7 @@
"version": "3.3.0",
"resolved": "https://registry.npmjs.org/lie/-/lie-3.3.0.tgz",
"integrity": "sha512-UaiMJzeWRlEujzAuw5LokY1L5ecNQYZKfmyZ9L7wDHb/p5etKaxXhohBcrw0EYby+G/NA52vRSN4N39dxHAIwQ==",
+ "dev": true,
"dependencies": {
"immediate": "~3.0.5"
}
@@ -43651,7 +43654,8 @@
"node_modules/setimmediate": {
"version": "1.0.5",
"resolved": "https://registry.npmjs.org/setimmediate/-/setimmediate-1.0.5.tgz",
- "integrity": "sha512-MATJdZp8sLqDl/68LfQmbP8zKPLQNV6BIZoIgrscFDQ+RsvK/BxeDQOgyxKKoh0y/8h3BqVFnCqQ/gd+reiIXA=="
+ "integrity": "sha512-MATJdZp8sLqDl/68LfQmbP8zKPLQNV6BIZoIgrscFDQ+RsvK/BxeDQOgyxKKoh0y/8h3BqVFnCqQ/gd+reiIXA==",
+ "dev": true
},
"node_modules/setprototypeof": {
"version": "1.2.0",
@@ -68413,7 +68417,8 @@
"immediate": {
"version": "3.0.6",
"resolved": "https://registry.npmjs.org/immediate/-/immediate-3.0.6.tgz",
- "integrity": "sha512-XXOFtyqDjNDAQxVfYxuF7g9Il/IbWmmlQg2MYKOH8ExIT1qg6xc4zyS3HaEEATgs1btfzxq15ciUiY7gjSXRGQ=="
+ "integrity": "sha512-XXOFtyqDjNDAQxVfYxuF7g9Il/IbWmmlQg2MYKOH8ExIT1qg6xc4zyS3HaEEATgs1btfzxq15ciUiY7gjSXRGQ==",
+ "dev": true
},
"immer": {
"version": "9.0.6",
@@ -73017,6 +73022,7 @@
"version": "3.10.1",
"resolved": "https://registry.npmjs.org/jszip/-/jszip-3.10.1.tgz",
"integrity": "sha512-xXDvecyTpGLrqFrvkrUSoxxfJI5AH7U8zxxtVclpsUtMCq4JQ290LY8AW5c7Ggnr/Y/oK+bQMbqK2qmtk3pN4g==",
+ "dev": true,
"requires": {
"lie": "~3.3.0",
"pako": "~1.0.2",
@@ -73027,7 +73033,8 @@
"pako": {
"version": "1.0.11",
"resolved": "https://registry.npmjs.org/pako/-/pako-1.0.11.tgz",
- "integrity": "sha512-4hLB8Py4zZce5s4yd9XzopqwVv/yGNhV1Bl8NTmCq1763HeK2+EwVTv+leGeL13Dnh2wfbqowVPXCIO0z4taYw=="
+ "integrity": "sha512-4hLB8Py4zZce5s4yd9XzopqwVv/yGNhV1Bl8NTmCq1763HeK2+EwVTv+leGeL13Dnh2wfbqowVPXCIO0z4taYw==",
+ "dev": true
}
}
},
@@ -73261,6 +73268,7 @@
"version": "3.3.0",
"resolved": "https://registry.npmjs.org/lie/-/lie-3.3.0.tgz",
"integrity": "sha512-UaiMJzeWRlEujzAuw5LokY1L5ecNQYZKfmyZ9L7wDHb/p5etKaxXhohBcrw0EYby+G/NA52vRSN4N39dxHAIwQ==",
+ "dev": true,
"requires": {
"immediate": "~3.0.5"
}
@@ -82506,7 +82514,8 @@
"setimmediate": {
"version": "1.0.5",
"resolved": "https://registry.npmjs.org/setimmediate/-/setimmediate-1.0.5.tgz",
- "integrity": "sha512-MATJdZp8sLqDl/68LfQmbP8zKPLQNV6BIZoIgrscFDQ+RsvK/BxeDQOgyxKKoh0y/8h3BqVFnCqQ/gd+reiIXA=="
+ "integrity": "sha512-MATJdZp8sLqDl/68LfQmbP8zKPLQNV6BIZoIgrscFDQ+RsvK/BxeDQOgyxKKoh0y/8h3BqVFnCqQ/gd+reiIXA==",
+ "dev": true
},
"setprototypeof": {
"version": "1.2.0",