Skip to content

Commit 8dda8ed

Browse files
committed
fix: Add path and pathname
1 parent 82d71c3 commit 8dda8ed

File tree

3 files changed

+38
-33
lines changed

3 files changed

+38
-33
lines changed

CoCreate.config.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,16 @@ module.exports = {
88
"object": {
99
"_id": "61a12db2a8b6b4001a9f5a2e",
1010
"name": "index.html",
11-
"path": "/docs/file/index.html",
11+
"path": "/docs/file/",
12+
"pathname": "/docs/file/index.html",
1213
"src": "{{./docs/index.html}}",
1314
"host": [
1415
"*",
1516
"general.cocreate.app"
1617
],
17-
"directory": "/docs/file",
18-
"parentDirectory": "{{parentDirectory}}",
18+
"directory": "file",
1919
"content-type": "{{content-type}}",
20-
"public": "true",
21-
"website_id": "644d4bff8036fb9d1d1fd69c"
20+
"public": "true"
2221
}
2322
}
2423
]

src/client.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,8 @@ async function fileEvent(event) {
117117
files[i] = await readFile(files[i])
118118

119119
files[i].directory = handle.directory || '/'
120-
files[i].parentDirectory = handle.parentDirectory || ''
121-
files[i].path = handle.path || '/' + handle.name
120+
files[i].path = handle.path || '/'
121+
files[i].pathname = handle.pathname || '/' + handle.name
122122
files[i]['content-type'] = files[i].type
123123
files[i].input = input
124124
files[i].id = await getFileId(files[i])
@@ -159,9 +159,9 @@ async function fileEvent(event) {
159159
async function getDirectoryHandles(handle, name) {
160160
let handles = [];
161161
for await (const entry of handle.values()) {
162-
entry.directory = '/' + name
163-
entry.parentDirectory = name.split("/").pop();
164-
entry.path = '/' + name + '/' + entry.name
162+
entry.directory = name
163+
entry.path = '/' + name + '/'
164+
entry.pathname = '/' + name + '/' + entry.name
165165
if (!entry.webkitRelativePath)
166166
entry.webkitRelativePath = name
167167

@@ -631,8 +631,8 @@ async function create(directory, type, name, src = "") {
631631
}
632632

633633
if (directory.input) {
634-
file.directory = directory.path
635-
file.parentDirectory = directory.name
634+
file.directory = directory.name
635+
file.pathname = directory.path + '/' + file.name
636636
file.path = directory.path + '/' + file.name
637637
file.input = directory.input
638638
file.handle = handle

src/server.js

Lines changed: 27 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ module.exports = async function file(CoCreateConfig, configPath, match) {
121121

122122

123123
crud.socket.create(config)
124-
config.broadcastSender = false
124+
// config.broadcastBrowser = false
125125

126126
if (config.email && config.password) {
127127
let request = {
@@ -195,14 +195,9 @@ module.exports = async function file(CoCreateConfig, configPath, match) {
195195
let name = file
196196
let source = ''
197197
let directoryName = parentDirectory || '';
198-
let parentDirectoryOnly = parentDirectory || '';
199-
let index = parentDirectoryOnly.lastIndexOf('/') + 1
200-
if (parentDirectoryOnly && index) {
201-
parentDirectoryOnly = parentDirectoryOnly.substring(index)
202-
}
198+
203199
const fileExtension = path.extname(file);
204200
let mimeType = mimeTypes[fileExtension]
205-
let pathName = '';
206201

207202
if (!directoryName && directory.object && directory.object.directory)
208203
directoryName = directory.object.directory.replace('{{directory}}', '').trim()
@@ -211,12 +206,23 @@ module.exports = async function file(CoCreateConfig, configPath, match) {
211206

212207
if (exclude && exclude.includes(directoryName)) continue
213208

209+
let Path = '';
214210
if (directoryName.endsWith("/"))
215-
pathName = directoryName + name
211+
Path = directoryName
216212
else if (directoryName)
217-
pathName = directoryName + '/' + name
213+
Path = directoryName + '/'
218214
else
219-
pathName = '/' + name
215+
Path = '/'
216+
217+
let pathname = Path + name;
218+
219+
let folder = ''
220+
if (Path === '/')
221+
folder = Path
222+
else {
223+
let result = Path.split('/');
224+
folder = result[result.length - 2];
225+
}
220226

221227
if (isDirectory)
222228
mimeType = "text/directory"
@@ -226,9 +232,9 @@ module.exports = async function file(CoCreateConfig, configPath, match) {
226232
let values = {
227233
'{{name}}': name,
228234
'{{source}}': source,
229-
'{{directory}}': directoryName,
230-
'{{parentDirectory}}': parentDirectoryOnly,
231-
'{{path}}': pathName,
235+
'{{directory}}': folder,
236+
'{{path}}': Path,
237+
'{{pathname}}': pathname,
232238
'{{content-type}}': mimeType
233239
}
234240

@@ -239,10 +245,10 @@ module.exports = async function file(CoCreateConfig, configPath, match) {
239245
object.src = "{{source}}"
240246
if (!object.directory)
241247
object.directory = "/{{directory}}"
242-
if (!object.parentDirectory)
243-
object.parentDirectory = "{{parentDirectory}}"
244248
if (!object.path)
245249
object.path = "{{path}}"
250+
if (!object.pathname)
251+
object.pathname = "{{pathname}}"
246252
if (!object["content-type"])
247253
object["content-type"] = '{{content-type}}'
248254
if (!object.public && object.public != false && object.public != 'false')
@@ -259,7 +265,7 @@ module.exports = async function file(CoCreateConfig, configPath, match) {
259265
if (variables) {
260266
for (let variable of variables) {
261267
if (variable == '{{directory}}') {
262-
if (parentDirectory)
268+
if (folder)
263269
newObject.object[key] = values[variable]
264270
else
265271
newObject.object[key] = newObject.object[key].replace(variable, '');
@@ -276,21 +282,21 @@ module.exports = async function file(CoCreateConfig, configPath, match) {
276282

277283
if (!newObject.object._id)
278284
newObject.$filter = {
279-
query: [{ key: 'path', value: pathName, operator: '$or' }]
285+
query: [{ key: 'pathname', value: pathname, operator: '$or' }]
280286
}
281287

282288
response = await runStore(newObject);
283289
if (response.error)
284290
errorLog.push(response.error)
285291

286-
if (isDirectory && pathName) {
292+
if (isDirectory && pathname) {
287293
let newEntry
288294
if (entry.endsWith("/"))
289295
newEntry = entry + name
290296
else
291297
newEntry = entry + '/' + name
292298

293-
await runFiles(directory, newEntry, exclude, pathName)
299+
await runFiles(directory, newEntry, exclude, pathname)
294300
}
295301
}
296302
if (errorLog.length)
@@ -377,9 +383,9 @@ module.exports = async function file(CoCreateConfig, configPath, match) {
377383
}
378384

379385
let data = { array, object }
380-
if (!object._id && object.path)
386+
if (!object._id && object.pathname)
381387
data.$filter = {
382-
query: [{ key: 'path', value: object.path, operator: '$or' }]
388+
query: [{ key: 'pathname', value: object.pathname, operator: '$or' }]
383389
}
384390

385391
if (match.length && isMatch)

0 commit comments

Comments
 (0)