@tryghost/mg-fs-utils 0.10.4 → 0.11.0
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/FileCache.js +10 -21
- package/package.json +4 -3
package/lib/FileCache.js
CHANGED
|
@@ -5,6 +5,7 @@ import _ from 'lodash';
|
|
|
5
5
|
import fs from 'fs-extra';
|
|
6
6
|
import imageTransform from '@tryghost/image-transform';
|
|
7
7
|
import errors from '@tryghost/errors';
|
|
8
|
+
import transliterate from 'transliteration';
|
|
8
9
|
import csv from './csv.js';
|
|
9
10
|
|
|
10
11
|
const basePath = 'mg';
|
|
@@ -131,24 +132,12 @@ class FileCache {
|
|
|
131
132
|
return (mb * 1048576);
|
|
132
133
|
}
|
|
133
134
|
|
|
134
|
-
// @TODO: move this somewhere shared,
|
|
135
|
-
// it's currently duplicated from https://github.com/TryGhost/Ghost-Storage-Base/blob/main/BaseStorage.js#L63
|
|
136
135
|
sanitizeFileName(src) {
|
|
137
|
-
let
|
|
136
|
+
let fileNameNoExt = path.parse(src).name;
|
|
138
137
|
|
|
139
|
-
|
|
140
|
-
src = src.replace(src, this.sanitizeDirName(src));
|
|
138
|
+
let safeFileNameNoExt = transliterate.slugify(fileNameNoExt);
|
|
141
139
|
|
|
142
|
-
|
|
143
|
-
// below only matches ascii characters, @, and .
|
|
144
|
-
// unicode filenames like город.zip would therefore resolve to ----.zip
|
|
145
|
-
return src.replace(basename, basename.replace(/[^\w@.]/gi, '-'));
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
sanitizeDirName(src) {
|
|
149
|
-
// Slighly different regex from sanitizing the filename, as we still want to
|
|
150
|
-
// support characters like `/`, `_`, and `-`
|
|
151
|
-
return src.replace(/[^\w@./-_]/gi, '-');
|
|
140
|
+
return src.replace(fileNameNoExt, safeFileNameNoExt);
|
|
152
141
|
}
|
|
153
142
|
|
|
154
143
|
resolveImageFileName(filename) {
|
|
@@ -183,6 +172,12 @@ class FileCache {
|
|
|
183
172
|
typePath = this.filesPath;
|
|
184
173
|
}
|
|
185
174
|
|
|
175
|
+
// remove the base filePath if it already exists in the path, so we don't get nested filePath directories
|
|
176
|
+
filename = filename.replace(`/${typePath}`, '');
|
|
177
|
+
|
|
178
|
+
// replace the basename part with a sanitized version
|
|
179
|
+
filename = filename.replace(filename, this.sanitizeFileName(filename));
|
|
180
|
+
|
|
186
181
|
// CASE: Some image URLs are very long and can cause various issues with storage.
|
|
187
182
|
// If the filepath is more than 200 characters, slice the last 200 and use that
|
|
188
183
|
let theBasename = path.basename(filename);
|
|
@@ -192,12 +187,6 @@ class FileCache {
|
|
|
192
187
|
filename = path.join('/', shorter, theBasename);
|
|
193
188
|
}
|
|
194
189
|
|
|
195
|
-
// remove the base filePath if it already exists in the path, so we don't get nested filePath directories
|
|
196
|
-
filename = filename.replace(`/${typePath}`, '');
|
|
197
|
-
|
|
198
|
-
// replace the basename part with a sanitized version
|
|
199
|
-
filename = filename.replace(filename, this.sanitizeFileName(filename));
|
|
200
|
-
|
|
201
190
|
// @TODO: use content type on request to infer this, rather than assuming jpeg?
|
|
202
191
|
if (type === 'image' && !_.includes(knownImageExtensions, ext)) {
|
|
203
192
|
if (!ext) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tryghost/mg-fs-utils",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.11.0",
|
|
4
4
|
"repository": "https://github.com/TryGhost/migrate/tree/main/packages/mg-fs-utils",
|
|
5
5
|
"author": "Ghost Foundation",
|
|
6
6
|
"license": "MIT",
|
|
@@ -33,7 +33,8 @@
|
|
|
33
33
|
"date-fns": "2.29.3",
|
|
34
34
|
"fs-extra": "10.1.0",
|
|
35
35
|
"lodash": "4.17.21",
|
|
36
|
-
"sharp": "0.31.
|
|
36
|
+
"sharp": "0.31.2",
|
|
37
|
+
"transliteration": "2.3.5"
|
|
37
38
|
},
|
|
38
|
-
"gitHead": "
|
|
39
|
+
"gitHead": "49293c6abb8c3d32ff2d7c97b90fbea25fe4a4ef"
|
|
39
40
|
}
|