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
b2ff064d
Unverified
Commit
b2ff064d
authored
Jul 12, 2020
by
Regev Brody
Committed by
GitHub
Jul 12, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: stream assets from storage local locations (#2087)
parent
57f5cbd5
Show whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
84 additions
and
19 deletions
+84
-19
assets.js
server/models/assets.js
+40
-18
storage.js
server/models/storage.js
+17
-0
storage.js
server/modules/storage/azure/storage.js
+3
-0
storage.js
server/modules/storage/box/storage.js
+3
-0
storage.js
server/modules/storage/disk/storage.js
+3
-1
storage.js
server/modules/storage/dropbox/storage.js
+3
-0
storage.js
server/modules/storage/gdrive/storage.js
+3
-0
storage.js
server/modules/storage/git/storage.js
+3
-0
storage.js
server/modules/storage/onedrive/storage.js
+3
-0
common.js
server/modules/storage/s3/common.js
+3
-0
storage.js
server/modules/storage/sftp/storage.js
+3
-0
No files found.
server/models/assets.js
View file @
b2ff064d
...
...
@@ -6,6 +6,7 @@ const path = require('path')
const
fs
=
require
(
'fs-extra'
)
const
_
=
require
(
'lodash'
)
const
assetHelper
=
require
(
'../helpers/asset'
)
const
Promise
=
require
(
'bluebird'
)
/**
* Users model
...
...
@@ -150,32 +151,53 @@ module.exports = class Asset extends Model {
}
static
async
getAsset
(
assetPath
,
res
)
{
let
assetExists
=
await
WIKI
.
models
.
assets
.
getAssetFromCache
(
assetPath
,
res
)
if
(
!
assetExists
)
{
await
WIKI
.
models
.
assets
.
getAssetFromDb
(
assetPath
,
res
)
}
}
static
async
getAssetFromCache
(
assetPath
,
res
)
{
try
{
const
fileHash
=
assetHelper
.
generateHash
(
assetPath
)
const
cachePath
=
path
.
resolve
(
WIKI
.
ROOTPATH
,
WIKI
.
config
.
dataPath
,
`cache/
${
fileHash
}
.dat`
)
if
(
await
WIKI
.
models
.
assets
.
getAssetFromCache
(
assetPath
,
cachePath
,
res
))
{
return
}
if
(
await
WIKI
.
models
.
assets
.
getAssetFromStorage
(
assetPath
,
res
))
{
return
}
await
WIKI
.
models
.
assets
.
getAssetFromDb
(
assetPath
,
fileHash
,
cachePath
,
res
)
}
catch
(
err
)
{
if
(
err
.
code
===
`ECONNABORTED`
||
err
.
code
===
`EPIPE`
)
{
return
}
WIKI
.
logger
.
error
(
err
)
res
.
sendStatus
(
500
)
}
}
return
new
Promise
((
resolve
,
reject
)
=>
{
static
async
getAssetFromCache
(
assetPath
,
cachePath
,
res
)
{
try
{
await
fs
.
access
(
cachePath
,
fs
.
constants
.
R_OK
)
}
catch
(
err
)
{
return
false
}
const
sendFile
=
Promise
.
promisify
(
res
.
sendFile
,
{
context
:
res
})
res
.
type
(
path
.
extname
(
assetPath
))
res
.
sendFile
(
cachePath
,
{
dotfiles
:
'deny'
},
err
=>
{
if
(
err
)
{
resolve
(
false
)
}
else
{
resolve
(
true
)
await
sendFile
(
cachePath
,
{
dotfiles
:
'deny'
})
return
true
}
static
async
getAssetFromStorage
(
assetPath
,
res
)
{
const
localLocations
=
await
WIKI
.
models
.
storage
.
getLocalLocations
({
asset
:
{
path
:
assetPath
,
}
})
})
for
(
let
location
of
_
.
filter
(
localLocations
,
location
=>
Boolean
(
location
.
path
)))
{
const
assetExists
=
await
WIKI
.
models
.
assets
.
getAssetFromCache
(
assetPath
,
location
.
path
,
res
)
if
(
assetExists
)
{
return
true
}
}
return
false
}
static
async
getAssetFromDb
(
assetPath
,
res
)
{
const
fileHash
=
assetHelper
.
generateHash
(
assetPath
)
const
cachePath
=
path
.
resolve
(
WIKI
.
ROOTPATH
,
WIKI
.
config
.
dataPath
,
`cache/
${
fileHash
}
.dat`
)
static
async
getAssetFromDb
(
assetPath
,
fileHash
,
cachePath
,
res
)
{
const
asset
=
await
WIKI
.
models
.
assets
.
query
().
where
(
'hash'
,
fileHash
).
first
()
if
(
asset
)
{
const
assetData
=
await
WIKI
.
models
.
knex
(
'assetData'
).
where
(
'id'
,
asset
.
id
).
first
()
...
...
server/models/storage.js
View file @
b2ff064d
...
...
@@ -199,6 +199,23 @@ module.exports = class Storage extends Model {
}
}
static
async
getLocalLocations
({
asset
})
{
const
locations
=
[]
const
promises
=
this
.
targets
.
map
(
async
(
target
)
=>
{
try
{
const
path
=
await
target
.
fn
.
getLocalLocation
(
asset
)
locations
.
push
({
path
,
key
:
target
.
key
})
}
catch
(
err
)
{
WIKI
.
logger
.
warn
(
err
)
}
})
await
Promise
.
all
(
promises
)
return
locations
}
static
async
executeAction
(
targetKey
,
handler
)
{
try
{
const
target
=
_
.
find
(
this
.
targets
,
[
'key'
,
targetKey
])
...
...
server/modules/storage/azure/storage.js
View file @
b2ff064d
...
...
@@ -115,6 +115,9 @@ module.exports = {
deleteSnapshots
:
'include'
})
},
async
getLocalLocation
()
{
},
/**
* HANDLERS
*/
...
...
server/modules/storage/box/storage.js
View file @
b2ff064d
...
...
@@ -19,5 +19,8 @@ module.exports = {
},
async
renamed
()
{
},
async
getLocalLocation
()
{
}
}
server/modules/storage/disk/storage.js
View file @
b2ff064d
...
...
@@ -116,7 +116,9 @@ module.exports = {
WIKI
.
logger
.
info
(
`(STORAGE/DISK) Renaming file from
${
asset
.
path
}
to
${
asset
.
destinationPath
}
...`
)
await
fs
.
move
(
path
.
join
(
this
.
config
.
path
,
asset
.
path
),
path
.
join
(
this
.
config
.
path
,
asset
.
destinationPath
),
{
overwrite
:
true
})
},
async
getLocalLocation
(
asset
)
{
return
path
.
join
(
this
.
config
.
path
,
asset
.
path
)
},
/**
* HANDLERS
*/
...
...
server/modules/storage/dropbox/storage.js
View file @
b2ff064d
...
...
@@ -19,5 +19,8 @@ module.exports = {
},
async
renamed
()
{
},
async
getLocalLocation
()
{
}
}
server/modules/storage/gdrive/storage.js
View file @
b2ff064d
...
...
@@ -19,5 +19,8 @@ module.exports = {
},
async
renamed
()
{
},
async
getLocalLocation
()
{
}
}
server/modules/storage/git/storage.js
View file @
b2ff064d
...
...
@@ -363,6 +363,9 @@ module.exports = {
'--author'
:
`"
${
asset
.
moveAuthorName
}
<
${
asset
.
moveAuthorEmail
}
>"`
})
},
async
getLocalLocation
(
asset
)
{
return
path
.
join
(
this
.
repoPath
,
asset
.
path
)
},
/**
* HANDLERS
*/
...
...
server/modules/storage/onedrive/storage.js
View file @
b2ff064d
...
...
@@ -19,5 +19,8 @@ module.exports = {
},
async
renamed
()
{
},
async
getLocalLocation
()
{
}
}
server/modules/storage/s3/common.js
View file @
b2ff064d
...
...
@@ -120,6 +120,9 @@ module.exports = class S3CompatibleStorage {
await
this
.
s3
.
copyObject
({
CopySource
:
asset
.
path
,
Key
:
asset
.
destinationPath
}).
promise
()
await
this
.
s3
.
deleteObject
({
Key
:
asset
.
path
}).
promise
()
}
async
getLocalLocation
()
{
}
/**
* HANDLERS
*/
...
...
server/modules/storage/sftp/storage.js
View file @
b2ff064d
...
...
@@ -104,6 +104,9 @@ module.exports = {
await
this
.
ensureDirectory
(
asset
.
destinationPath
)
await
this
.
sftp
.
rename
(
path
.
posix
.
join
(
this
.
config
.
basePath
,
asset
.
path
),
path
.
posix
.
join
(
this
.
config
.
basePath
,
asset
.
destinationPath
))
},
async
getLocalLocation
()
{
},
/**
* HANDLERS
*/
...
...
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