Setup eslint and enforce rules
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
@@ -1,9 +1,9 @@
|
||||
import {FileMetadata, FileNotFoundError, Filesystem, Stat} from "./Filesystem"
|
||||
import * as fs from "fs"
|
||||
import * as path from "path"
|
||||
import {UniversalPath} from "../path"
|
||||
import * as rimraf from "rimraf"
|
||||
import * as mkdirp from "mkdirp"
|
||||
import {FileMetadata, FileNotFoundError, Filesystem, Stat} from './Filesystem'
|
||||
import * as fs from 'fs'
|
||||
import * as path from 'path'
|
||||
import {UniversalPath} from '../path'
|
||||
import * as rimraf from 'rimraf'
|
||||
import * as mkdirp from 'mkdirp'
|
||||
|
||||
export interface LocalFilesystemConfig {
|
||||
baseDir: string
|
||||
@@ -15,8 +15,10 @@ export interface LocalFilesystemConfig {
|
||||
*/
|
||||
export class LocalFilesystem extends Filesystem {
|
||||
constructor(
|
||||
protected readonly baseConfig: LocalFilesystemConfig
|
||||
) { super() }
|
||||
protected readonly baseConfig: LocalFilesystemConfig,
|
||||
) {
|
||||
super()
|
||||
}
|
||||
|
||||
async open(): Promise<void> {
|
||||
// Make sure the base directory exists
|
||||
@@ -26,14 +28,14 @@ export class LocalFilesystem extends Filesystem {
|
||||
}
|
||||
|
||||
public getPrefix(): string {
|
||||
return 'local://'
|
||||
return 'file://'
|
||||
}
|
||||
|
||||
public async putLocalFile({localPath, storePath, ...args}: {localPath: string, storePath: string, mimeType?: string, tags?: string[], tag?: string}) {
|
||||
public async putLocalFile({localPath, storePath, ...args}: {localPath: string, storePath: string, mimeType?: string, tags?: string[], tag?: string}): Promise<void> {
|
||||
await fs.promises.copyFile(localPath, this.storePath(storePath))
|
||||
await fs.promises.writeFile(this.metadataPath(storePath), JSON.stringify({
|
||||
mimeType: args.mimeType,
|
||||
tags: this._normalizeTags(args.tag, args.tags),
|
||||
tags: this.normalizeTags(args.tag, args.tags),
|
||||
}))
|
||||
}
|
||||
|
||||
@@ -51,13 +53,13 @@ export class LocalFilesystem extends Filesystem {
|
||||
return fs.createWriteStream(this.storePath(args.storePath))
|
||||
}
|
||||
|
||||
public async getMetadata(storePath: string) {
|
||||
public async getMetadata(storePath: string): Promise<FileMetadata> {
|
||||
try {
|
||||
const json = (await fs.promises.readFile(this.metadataPath(storePath))).toString('utf-8')
|
||||
return JSON.parse(json)
|
||||
} catch (e) {
|
||||
return {
|
||||
tags: []
|
||||
tags: [],
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -81,7 +83,7 @@ export class LocalFilesystem extends Filesystem {
|
||||
exists: true,
|
||||
sizeInBytes: stat.size,
|
||||
mimeType: meta.mimeType,
|
||||
tags: meta.tags,
|
||||
tags: meta.tags ?? [],
|
||||
accessed: stat.atime,
|
||||
modified: stat.mtime,
|
||||
created: stat.ctime,
|
||||
@@ -92,7 +94,7 @@ export class LocalFilesystem extends Filesystem {
|
||||
path: new UniversalPath(args.storePath, this),
|
||||
exists: false,
|
||||
sizeInBytes: 0,
|
||||
tags: []
|
||||
tags: [],
|
||||
}
|
||||
}
|
||||
|
||||
@@ -107,9 +109,13 @@ export class LocalFilesystem extends Filesystem {
|
||||
fs.utimes(storePath, time, time, err => {
|
||||
if ( err ) {
|
||||
fs.open(storePath, 'w', (err2, fd) => {
|
||||
if ( err2 ) return rej(err2)
|
||||
if ( err2 ) {
|
||||
return rej(err2)
|
||||
}
|
||||
fs.close(fd, err3 => {
|
||||
if ( err3 ) return rej(err3)
|
||||
if ( err3 ) {
|
||||
return rej(err3)
|
||||
}
|
||||
res()
|
||||
})
|
||||
})
|
||||
@@ -127,9 +133,11 @@ export class LocalFilesystem extends Filesystem {
|
||||
} else {
|
||||
await new Promise<void>((res, rej) => {
|
||||
rimraf(this.storePath(args.storePath), err => {
|
||||
if ( err ) return rej(err)
|
||||
else {
|
||||
fs.promises.unlink(this.metadataPath(args.storePath)).then(() => res()).catch(rej)
|
||||
if ( err ) {
|
||||
return rej(err)
|
||||
} else {
|
||||
fs.promises.unlink(this.metadataPath(args.storePath)).then(() => res())
|
||||
.catch(rej)
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user