@tryghost/mg-fs-utils 0.9.2 → 0.9.3

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.
Files changed (2) hide show
  1. package/lib/FileCache.js +26 -0
  2. package/package.json +3 -3
package/lib/FileCache.js CHANGED
@@ -48,6 +48,8 @@ class FileCache {
48
48
  * - image files
49
49
  * - /content/media
50
50
  * - non-image media files like videos or audio files
51
+ * - /content/files
52
+ * - non-image and non-media files like pdfs
51
53
  */
52
54
  get cacheDir() {
53
55
  if (!this._cacheDir) {
@@ -58,6 +60,7 @@ class FileCache {
58
60
  if (this.options && this.options.contentDir) {
59
61
  fs.mkdirpSync(path.join(this.imageDir));
60
62
  fs.mkdirpSync(path.join(this.mediaDir));
63
+ fs.mkdirpSync(path.join(this.filesDir));
61
64
  } else {
62
65
  fs.mkdirpSync(path.join(this.zipDir));
63
66
  }
@@ -93,6 +96,14 @@ class FileCache {
93
96
  return path.join(this.zipDir, this.mediaPath);
94
97
  }
95
98
 
99
+ get filesPath() {
100
+ return path.join('content', 'files');
101
+ }
102
+
103
+ get filesDir() {
104
+ return path.join(this.zipDir, this.filesPath);
105
+ }
106
+
96
107
  get defaultCacheFileName() {
97
108
  if (this.batchName) {
98
109
  return `gh-${this.cacheName}-batch-${this.batchName}-${Date.now()}`;
@@ -167,6 +178,9 @@ class FileCache {
167
178
  } else if (type === 'media') {
168
179
  typeDir = this.mediaDir;
169
180
  typePath = this.mediaPath;
181
+ } else {
182
+ typeDir = this.filesDir;
183
+ typePath = this.filesPath;
170
184
  }
171
185
 
172
186
  // CASE: Some image URLs are very long and can cause various issues with storage.
@@ -232,6 +246,18 @@ class FileCache {
232
246
  return await fs.readJson(filepath);
233
247
  }
234
248
 
249
+ /**
250
+ * Read a JSON file containing temporary data
251
+ *
252
+ * @param {String} filename - name of file to read
253
+ */
254
+ hasTmpJSONFile(filename) {
255
+ let fileNameWithExt = (filename.endsWith('.json')) ? filename : `${filename}.json`; // Ensure the `.json` extension is only added if needed
256
+ let filepath = path.join(this.tmpDir, fileNameWithExt);
257
+
258
+ return fs.existsSync(filepath);
259
+ }
260
+
235
261
  /**
236
262
  * Create a CSV or JSON file with our processed data
237
263
  *
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tryghost/mg-fs-utils",
3
- "version": "0.9.2",
3
+ "version": "0.9.3",
4
4
  "repository": "https://github.com/TryGhost/migrate/tree/main/packages/mg-fs-utils",
5
5
  "author": "Ghost Foundation",
6
6
  "license": "MIT",
@@ -19,7 +19,7 @@
19
19
  "access": "public"
20
20
  },
21
21
  "dependencies": {
22
- "@tryghost/errors": "1.2.15",
22
+ "@tryghost/errors": "1.2.17",
23
23
  "@tryghost/image-transform": "1.2.2",
24
24
  "@tryghost/zip": "1.1.28",
25
25
  "adm-zip": "0.5.9",
@@ -29,5 +29,5 @@
29
29
  "lodash": "4.17.21",
30
30
  "sharp": "0.31.0"
31
31
  },
32
- "gitHead": "370c7f9973e7518cfb6433e694c8fbbf022c32cf"
32
+ "gitHead": "eb8c218c3b133ec2babb7c1911a8792d95c7e976"
33
33
  }