-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(Filesystem): Replace walk with filesystem, Next doesn't use __di…
…rname
- Loading branch information
Showing
8 changed files
with
179 additions
and
145 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import local from './local' | ||
|
||
const errorSchema = (message) => ({ galleries: [], error: { message } }) | ||
|
||
export default async function handler(req, res) { | ||
switch (req.method) { | ||
case 'GET': { | ||
const out = await local.get() | ||
return res.status(out.status).json(out.body) | ||
} | ||
default: | ||
return res.status(405).json(errorSchema(`Method ${req.method} Not Allowed`)) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import globCallback from 'glob' | ||
import path from 'path' | ||
import { promisify } from 'util' | ||
|
||
import utils from './utils' | ||
|
||
const glob = promisify(globCallback) | ||
|
||
async function get(destPath = '') { | ||
const publicPath = utils.safePublicPath('/') | ||
const globPath = path.join(publicPath, destPath) | ||
|
||
if (!globPath.startsWith(publicPath)) { | ||
throw new URIError('Invalid system path') | ||
} | ||
|
||
const files = await glob(decodeURI(`${globPath}/*`)) | ||
|
||
const webPaths = files.map((file) => { | ||
const fileMeta = {} | ||
fileMeta.ext = utils.type(file) // case-insensitive | ||
fileMeta.name = path.basename(file, `.${fileMeta.ext}`) | ||
fileMeta.filename = (fileMeta.ext === '') ? fileMeta.name : `${fileMeta.name}.${fileMeta.ext}` | ||
fileMeta.path = file.replace(globPath, destPath) | ||
|
||
const mediumType = utils.mediumType(utils.mimeType(fileMeta.ext)) | ||
fileMeta.mediumType = mediumType || 'folder' | ||
|
||
return fileMeta | ||
}) | ||
|
||
return { body: { files: webPaths, destPath }, status: 200 } | ||
} | ||
|
||
export default { | ||
get, | ||
} |
Oops, something went wrong.