Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
W
wiki-js
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
1
Issues
1
List
Board
Labels
Milestones
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jacklull
wiki-js
Commits
1fecf380
Commit
1fecf380
authored
May 21, 2019
by
Nick
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: upload file hash order
parent
eedd1c07
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
13 additions
and
6 deletions
+13
-6
upload.js
server/controllers/upload.js
+1
-1
assetFolders.js
server/models/assetFolders.js
+11
-3
assets.js
server/models/assets.js
+1
-2
No files found.
server/controllers/upload.js
View file @
1fecf380
...
...
@@ -87,7 +87,7 @@ router.post('/u', multer({
...
fileMeta
,
originalname
:
sanitize
(
fileMeta
.
originalname
).
toLowerCase
(),
folderId
:
folderId
,
hierarchy
,
assetPath
,
userId
:
req
.
user
.
id
})
res
.
send
(
'ok'
)
...
...
server/models/assetFolders.js
View file @
1fecf380
/* global WIKI */
const
Model
=
require
(
'objection'
).
Model
const
_
=
require
(
'lodash'
)
/* global WIKI */
/**
* Users model
...
...
@@ -33,11 +34,18 @@ module.exports = class AssetFolder extends Model {
}
}
/**
* Get full folder hierarchy starting from specified folder to root
*
* @param {Number} folderId Id of the folder
*/
static
async
getHierarchy
(
folderId
)
{
return
WIKI
.
models
.
knex
.
withRecursive
(
'ancestors'
,
qb
=>
{
const
hier
=
await
WIKI
.
models
.
knex
.
withRecursive
(
'ancestors'
,
qb
=>
{
qb
.
select
(
'id'
,
'name'
,
'slug'
,
'parentId'
).
from
(
'assetFolders'
).
where
(
'id'
,
folderId
).
union
(
sqb
=>
{
sqb
.
select
(
'a.id'
,
'a.name'
,
'a.slug'
,
'a.parentId'
).
from
(
'assetFolders AS a'
).
join
(
'ancestors'
,
'ancestors.parentId'
,
'a.id'
)
})
}).
select
(
'*'
).
from
(
'ancestors'
)
// The ancestors are from children to grandparents, must reverse for correct path order.
return
_
.
reverse
(
hier
)
}
}
server/models/assets.js
View file @
1fecf380
...
...
@@ -67,8 +67,7 @@ module.exports = class Asset extends Model {
static
async
upload
(
opts
)
{
const
fileInfo
=
path
.
parse
(
opts
.
originalname
)
const
folderPath
=
opts
.
hierarchy
.
map
(
h
=>
h
.
slug
).
join
(
'/'
)
const
fileHash
=
opts
.
folderId
?
assetHelper
.
generateHash
(
`
${
folderPath
}
/
${
opts
.
originalname
}
`
)
:
assetHelper
.
generateHash
(
opts
.
originalname
)
const
fileHash
=
assetHelper
.
generateHash
(
opts
.
assetPath
)
// Create asset entry
const
asset
=
await
WIKI
.
models
.
assets
.
query
().
insert
({
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment