-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsnfs.ts
195 lines (161 loc) · 4.09 KB
/
snfs.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
export class SNFSError extends Error {}
export abstract class SNFS {
abstract login(options: LoginOptions): Promise<Session>;
abstract resume(session_token: string): Promise<Session>;
}
export abstract class Session {
abstract info(): SessionInfo;
abstract detail(): Promise<SessionDetail>;
abstract logout(): Promise<LogoutResult>;
abstract useradd(options: UseraddOptions): Promise<UserInfo>;
abstract usermod(userno: string, options: UsermodOptions): Promise<UserInfo>;
abstract userdel(userno: string): Promise<UserdelResult>;
abstract userlist(): Promise<UserInfo[]>;
abstract fs(): Promise<FileSystem>;
abstract fsget(fsno: string, options?: FsgetOptions): Promise<FileSystem>;
abstract fsresume(fs_token: string): Promise<FileSystem>;
abstract fsadd(options: FsaddOptions): Promise<FSInfo>;
abstract fsmod(fsno: string, options: FsmodOptions): Promise<FSInfo>;
abstract fsdel(fsno: string): Promise<FsdelResult>;
abstract fslist(): Promise<FSInfo[]>;
}
export abstract class FileSystem {
abstract info(): FileSystemInfo;
abstract detail(): Promise<FileSystemDetail>;
abstract readdir(path: string): Promise<ReaddirResult[]>;
abstract stat(path: string): Promise<StatResult>;
abstract writefile(path: string, data: Uint8Array, options?: WritefileOptions): Promise<WritefileResult>;
abstract readfile(path: string): Promise<ReadfileResult>;
abstract unlink(path: string): Promise<UnlinkResult>;
abstract move(path: string, newpath: string): Promise<MoveResult>;
}
export interface FileSystemDetail {
fs_token: string;
fs: FSDetail;
union: FSDetail[];
}
export interface FileSystemInfo {
fs_token: string;
fsno: string;
union: string[];
}
export interface FSAccess {
name: string;
fsno: string;
writeable: boolean;
}
export interface FsaddOptions {
name: string;
max_files?: number;
max_storage?: number;
max_depth?: number;
max_path?: number;
}
export interface FsdelResult {
}
export interface FSDetail {
name: string;
fsno: string;
limits: FSLimits;
usage: FSUsage;
}
export interface FsgetOptions {
writeable?: boolean; // Writable bit mask. Set to true to request a writeable fs.
union?: string[]; // Array of fsno
}
export interface FSInfo {
name: string;
fsno: string;
limits: FSLimits;
}
export interface FSLimits {
max_files: number;
max_storage: number;
max_depth: number;
max_path: number;
}
export interface FsmodOptions {
name?: string;
max_files?: number;
max_storage?: number;
max_depth?: number;
max_path?: number;
}
export interface FSUsage {
no_files: number;
bytes_used: number; // BigInt maybe?
}
export interface LoginOptions {
name: string;
password: string;
}
export interface LogoutResult {
}
export interface MoveResult {
}
export enum NodeKind {
File = 'file',
Directory = 'dir',
}
export interface ReaddirResult {
name: string;
kind: NodeKind;
// Below only for files.
ino?: string; // uuid, like inode number in other file systems
ctime?: Date;
mtime?: Date;
size?: number; // BigInt maybe?
writeable?: boolean;
}
export interface ReadfileResult {
data: Uint8Array;
}
export interface SessionDetail {
session_token: string;
user: UserInfo;
}
export interface SessionInfo {
session_token: string;
userno: string;
}
export interface StatResult {
name: string;
kind: NodeKind;
ino: string; // uuid, like inode number in other file systems
ctime: Date;
mtime: Date;
size: number; // BigInt maybe?
writeable: boolean;
}
export interface UnlinkResult {
}
export interface UseraddOptions {
name: string;
password: string;
admin?: boolean;
fs?: string | null;
union?: string[];
}
export interface UserdelResult {
}
export interface UserInfo {
userno: string;
name: string;
admin: boolean;
fs: FSAccess | null;
union: FSAccess[];
}
export interface UsermodOptions {
name?: string;
password?: string;
admin?: boolean;
fs?: string | null;
union?: string[];
}
export interface WritefileOptions {
// To preserve the ino of the file. Default is to not preserve.
truncate?: boolean;
}
export interface WritefileResult {
ino: string;
}