Files
T
Justin Lin f0a09ac4d9 Feat filegraph (#194)
* feat: update filegraph on touch command

* feat: update filegraph on mkdir

* feat: add different parsing opts for each command

* refactor: replace axios with fetch. put handleCommand to a new file

* feat: add config for mounting cli in dev stage

* refactor: clean up unused validators

* feat: add command handler for copy files. reuse resolvePath function

* feat: add rm handler, support specific files deletion. Glob not supported yet

* feat: handle discover cases that the folder is actually empty

* feat: handle discover empty folder better and support rmdir

* feat: handle mv command

* refactor: remove unused console logs
2025-04-29 20:40:02 +08:00

36 lines
836 B
TypeScript

import { basename } from './utils.js'
export interface FileObject {
path: string
type: 'file' | 'directory'
discovered: boolean
empty?: boolean
}
export default class File implements FileObject {
path: string
name: string
type: 'file' | 'directory'
discovered: boolean
empty?: boolean
constructor(obj: FileObject) {
this.path = obj.path.trimEnd()
this.name = basename(obj.path)
this.type = obj.type
this.discovered = obj.discovered
this.empty = obj.empty && obj.type === 'directory'
}
isDirectory() {
return this.type === 'directory'
}
contains(file: FileObject) {
if (!this.isDirectory()) return false
if (this.path === file.path) return true
const parentPath = this.path.endsWith('/') ? this.path : `${this.path}/`
return file.path.startsWith(parentPath)
}
}