File-based response support & static server
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
- Clean up UniversalPath implementation
- Use Readable/Writable types correctly for stream methods
- Add .list() methods for getting child files
- Make Response body specify explicit types and support
writing Readable streams to the body
- Create a static file server that supports directory listing
This commit is contained in:
@@ -4,6 +4,7 @@ import * as path from 'path'
|
||||
import {UniversalPath} from '../path'
|
||||
import * as rimraf from 'rimraf'
|
||||
import * as mkdirp from 'mkdirp'
|
||||
import { Collection } from '../../collection/Collection'
|
||||
|
||||
export interface LocalFilesystemConfig {
|
||||
baseDir: string
|
||||
@@ -87,6 +88,8 @@ export class LocalFilesystem extends Filesystem {
|
||||
accessed: stat.atime,
|
||||
modified: stat.mtime,
|
||||
created: stat.ctime,
|
||||
isDirectory: stat.isDirectory(),
|
||||
isFile: stat.isFile(),
|
||||
}
|
||||
} catch (e) {
|
||||
if ( e?.code === 'ENOENT' ) {
|
||||
@@ -95,6 +98,8 @@ export class LocalFilesystem extends Filesystem {
|
||||
exists: false,
|
||||
sizeInBytes: 0,
|
||||
tags: [],
|
||||
isFile: false,
|
||||
isDirectory: false,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -166,4 +171,13 @@ export class LocalFilesystem extends Filesystem {
|
||||
protected metadataPath(storePath: string): string {
|
||||
return path.resolve(this.baseConfig.baseDir, 'meta', storePath + '.json')
|
||||
}
|
||||
|
||||
/**
|
||||
* List all immediate children of the given path.
|
||||
* @param storePath
|
||||
*/
|
||||
public async list(storePath: string): Promise<Collection<string>> {
|
||||
const paths = await fs.promises.readdir(this.storePath(storePath))
|
||||
return Collection.collect<string>(paths)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user