@cocreate/file 1.10.0 → 1.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/CHANGELOG.md CHANGED
@@ -1,3 +1,15 @@
1
+ # [1.11.0](https://github.com/CoCreate-app/CoCreate-file/compare/v1.10.0...v1.11.0) (2023-11-12)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * bump dependencies for latest features ([c268d0f](https://github.com/CoCreate-app/CoCreate-file/commit/c268d0fa6ddf28a8149d7ab59f28cbd491eea9a1))
7
+
8
+
9
+ ### Features
10
+
11
+ * symlinks will find realpath to upload ([0984755](https://github.com/CoCreate-app/CoCreate-file/commit/0984755e91cfcf5e819130502d5541f97d8bb9b1))
12
+
1
13
  # [1.10.0](https://github.com/CoCreate-app/CoCreate-file/compare/v1.9.10...v1.10.0) (2023-11-09)
2
14
 
3
15
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cocreate/file",
3
- "version": "1.10.0",
3
+ "version": "1.11.0",
4
4
  "description": "A headless file uploader that uses HTML5 attributes for customization. Allows easy upload of files to server.",
5
5
  "keywords": [
6
6
  "file",
@@ -59,9 +59,9 @@
59
59
  "webpack-log": "^3.0.1"
60
60
  },
61
61
  "dependencies": {
62
- "@cocreate/actions": "^1.12.1",
63
- "@cocreate/config": "^1.6.6",
64
- "@cocreate/render": "^1.29.1",
65
- "@cocreate/utils": "^1.26.2"
62
+ "@cocreate/actions": "^1.12.3",
63
+ "@cocreate/config": "^1.6.8",
64
+ "@cocreate/render": "^1.30.1",
65
+ "@cocreate/utils": "^1.27.1"
66
66
  }
67
67
  }
package/src/server.js CHANGED
@@ -1,6 +1,8 @@
1
1
  const crud = require('@cocreate/crud-client')
2
2
  const Config = require('@cocreate/config')
3
3
  const fs = require('fs');
4
+ const realpathAsync = fs.promises.realpath;
5
+
4
6
  const path = require('path');
5
7
  const mimeTypes = {
6
8
  ".aac": "audio/aac",
@@ -168,8 +170,6 @@ module.exports = async function file(CoCreateConfig, configPath, match) {
168
170
  let files = fs.readdirSync(entryPath);
169
171
 
170
172
  for (let file of files) {
171
- if (fs.lstatSync(`${entryPath}/${file}`).isSymbolicLink())
172
- continue
173
173
  let skip = false
174
174
  for (let i = 0; i < exclude.length; i++) {
175
175
  if (file.includes(exclude)) {
@@ -179,7 +179,14 @@ module.exports = async function file(CoCreateConfig, configPath, match) {
179
179
  }
180
180
  if (skip) continue
181
181
 
182
- let isDirectory = fs.existsSync(`${entryPath}/${file}`) && fs.lstatSync(`${entryPath}/${file}`).isDirectory();
182
+ let isDirectory
183
+ let isSymlink = fs.lstatSync(`${entryPath}/${file}`).isSymbolicLink()
184
+ if (isSymlink) {
185
+ let symlinkPath = await realpathAsync(`${entryPath}/${file}`)
186
+ isDirectory = fs.existsSync(symlinkPath) && fs.lstatSync(symlinkPath).isDirectory()
187
+ } else
188
+ isDirectory = fs.existsSync(`${entryPath}/${file}`) && fs.lstatSync(`${entryPath}/${file}`).isDirectory()
189
+
183
190
  let name = file
184
191
  let source = ''
185
192
 
@@ -229,7 +236,7 @@ module.exports = async function file(CoCreateConfig, configPath, match) {
229
236
  if (isDirectory)
230
237
  mimeType = "text/directory"
231
238
  else
232
- source = getSource(`${entryPath}/${file}`, mimeType)
239
+ source = await getSource(`${entryPath}/${file}`, mimeType, isSymlink)
233
240
 
234
241
  let values = {
235
242
  '{{name}}': name || '',
@@ -303,13 +310,17 @@ module.exports = async function file(CoCreateConfig, configPath, match) {
303
310
  }
304
311
 
305
312
 
306
- function getSource(path, mimeType) {
313
+ async function getSource(path, mimeType, isSymlink) {
307
314
  let readType = 'utf8'
308
315
  if (mimeType === 'image/svg+xml') {
309
316
  readType = 'utf8';
310
317
  } else if (/^(image|audio|video)\/[-+.\w]+/.test(mimeType)) {
311
318
  readType = 'base64';
312
319
  }
320
+
321
+ if (isSymlink)
322
+ path = await realpathAsync(path)
323
+
313
324
  let binary = fs.readFileSync(path);
314
325
  let content = new Buffer.from(binary).toString(readType);
315
326