@usync/drive 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +7 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +1250 -0
- package/dist/providers/base.d.ts +33 -0
- package/dist/providers/dropbox.d.ts +23 -0
- package/dist/providers/googledrive.d.ts +26 -0
- package/dist/providers/index.d.ts +11 -0
- package/dist/providers/onedrive.d.ts +28 -0
- package/dist/providers/webdav.d.ts +37 -0
- package/dist/types.d.ts +34 -0
- package/dist/util.d.ts +1 -0
- package/package.json +28 -0
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { IRequestOptions } from '@gera2ld/common';
|
|
2
|
+
import { OAuth2Authorizer } from '@usync/oauth2';
|
|
3
|
+
import { IAuthConfig, IFilePath, IRemoteFile, IUserInfo } from '../types';
|
|
4
|
+
export type ITypedRequestOptions = IRequestOptions & {
|
|
5
|
+
responseType: 'json' | 'blob' | 'text';
|
|
6
|
+
};
|
|
7
|
+
export type IRequestFunction = <T>(url: string, options: ITypedRequestOptions) => Promise<T>;
|
|
8
|
+
export declare function withDelay(request: IRequestFunction): <T>(url: string, options: ITypedRequestOptions) => Promise<T>;
|
|
9
|
+
export declare function withToken(authorizer: OAuth2Authorizer, handleOAuth2?: (url: string) => Promise<string>): (request: IRequestFunction) => <T>(url: string, options: ITypedRequestOptions) => Promise<T>;
|
|
10
|
+
export declare abstract class DriveBase {
|
|
11
|
+
abstract mkdir(param: {
|
|
12
|
+
parent?: IFilePath;
|
|
13
|
+
name: string;
|
|
14
|
+
}): Promise<IRemoteFile>;
|
|
15
|
+
abstract find(param: IFilePath): Promise<IRemoteFile>;
|
|
16
|
+
abstract list(parent?: IFilePath): AsyncGenerator<IRemoteFile[]>;
|
|
17
|
+
abstract get(param: IFilePath): Promise<Blob>;
|
|
18
|
+
abstract remove(param: IFilePath): Promise<void>;
|
|
19
|
+
abstract put(param: IFilePath & {
|
|
20
|
+
parent?: IFilePath;
|
|
21
|
+
name?: string;
|
|
22
|
+
}, data: Blob): Promise<IRemoteFile>;
|
|
23
|
+
}
|
|
24
|
+
export declare abstract class AuthenticatedDriveBase extends DriveBase {
|
|
25
|
+
protected authConfig: IAuthConfig;
|
|
26
|
+
protected context: Record<string, unknown>;
|
|
27
|
+
baseUrl: string | undefined;
|
|
28
|
+
request: IRequestFunction;
|
|
29
|
+
constructor(authConfig: IAuthConfig, context: Record<string, unknown>);
|
|
30
|
+
initRequest(): IRequestFunction;
|
|
31
|
+
getAccount(): Promise<IUserInfo>;
|
|
32
|
+
}
|
|
33
|
+
export declare function unicodeReplacer(_key: string, value: unknown): unknown;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { IFilePath, IRemoteFile } from '../types';
|
|
2
|
+
import { AuthenticatedDriveBase } from './base';
|
|
3
|
+
export declare class Dropbox extends AuthenticatedDriveBase {
|
|
4
|
+
private normalizeEntry;
|
|
5
|
+
private getDropboxPath;
|
|
6
|
+
getAccount(): Promise<{
|
|
7
|
+
id: string;
|
|
8
|
+
name: string;
|
|
9
|
+
avatar: string;
|
|
10
|
+
}>;
|
|
11
|
+
mkdir(param: {
|
|
12
|
+
parent?: IFilePath;
|
|
13
|
+
name: string;
|
|
14
|
+
}): Promise<IRemoteFile>;
|
|
15
|
+
find(param: IFilePath): Promise<IRemoteFile>;
|
|
16
|
+
list(parent?: IFilePath): AsyncGenerator<IRemoteFile[], void, unknown>;
|
|
17
|
+
get(param: IFilePath): Promise<Blob>;
|
|
18
|
+
remove(param: IFilePath): Promise<void>;
|
|
19
|
+
put(param: IFilePath & {
|
|
20
|
+
parent?: IFilePath;
|
|
21
|
+
name?: string;
|
|
22
|
+
}, data: Blob): Promise<IRemoteFile>;
|
|
23
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { IFilePath, IRemoteFile } from '../types';
|
|
2
|
+
import { AuthenticatedDriveBase } from './base';
|
|
3
|
+
export declare class GoogleDrive extends AuthenticatedDriveBase {
|
|
4
|
+
baseUrl: string;
|
|
5
|
+
rootId: string;
|
|
6
|
+
getAccount(): Promise<{
|
|
7
|
+
id: string;
|
|
8
|
+
name: string;
|
|
9
|
+
avatar: string;
|
|
10
|
+
}>;
|
|
11
|
+
private normalizeEntry;
|
|
12
|
+
private stat;
|
|
13
|
+
private resolveId;
|
|
14
|
+
find(param: IFilePath): Promise<IRemoteFile>;
|
|
15
|
+
mkdir(param: {
|
|
16
|
+
parent?: IFilePath;
|
|
17
|
+
name: string;
|
|
18
|
+
}): Promise<IRemoteFile>;
|
|
19
|
+
list(parent?: IFilePath): AsyncGenerator<IRemoteFile[], void, unknown>;
|
|
20
|
+
get(param: IFilePath): Promise<Blob>;
|
|
21
|
+
remove(param: IFilePath): Promise<void>;
|
|
22
|
+
put(param: IFilePath & {
|
|
23
|
+
parent?: IFilePath;
|
|
24
|
+
name?: string;
|
|
25
|
+
}, data: Blob): Promise<IRemoteFile>;
|
|
26
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Dropbox } from './dropbox';
|
|
2
|
+
import { GoogleDrive } from './googledrive';
|
|
3
|
+
import { OneDrive } from './onedrive';
|
|
4
|
+
import { WebDav } from './webdav';
|
|
5
|
+
export * from './base';
|
|
6
|
+
export declare const DriveProviders: {
|
|
7
|
+
dropbox: typeof Dropbox;
|
|
8
|
+
googledrive: typeof GoogleDrive;
|
|
9
|
+
onedrive: typeof OneDrive;
|
|
10
|
+
webdav: typeof WebDav;
|
|
11
|
+
};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { IFilePath, IRemoteFile, IUserInfo } from '../types';
|
|
2
|
+
import { AuthenticatedDriveBase } from './base';
|
|
3
|
+
export interface IOneDriveItem {
|
|
4
|
+
id: string;
|
|
5
|
+
name: string;
|
|
6
|
+
size: number;
|
|
7
|
+
lastModifiedDateTime: string;
|
|
8
|
+
'@microsoft.graph.downloadUrl': string;
|
|
9
|
+
}
|
|
10
|
+
export declare class OneDrive extends AuthenticatedDriveBase {
|
|
11
|
+
baseUrl: string;
|
|
12
|
+
root: string;
|
|
13
|
+
getAccount(): Promise<IUserInfo>;
|
|
14
|
+
private normalizeEntry;
|
|
15
|
+
private getOneDrivePath;
|
|
16
|
+
mkdir(param: {
|
|
17
|
+
parent?: IFilePath;
|
|
18
|
+
name: string;
|
|
19
|
+
}): Promise<IRemoteFile>;
|
|
20
|
+
find(param: IFilePath): Promise<IRemoteFile>;
|
|
21
|
+
list(parent?: IFilePath): AsyncGenerator<IRemoteFile[], void, unknown>;
|
|
22
|
+
get(param: IFilePath): Promise<Blob>;
|
|
23
|
+
remove(param: IFilePath): Promise<void>;
|
|
24
|
+
put(param: IFilePath & {
|
|
25
|
+
parent?: IFilePath;
|
|
26
|
+
name?: string;
|
|
27
|
+
}, data: Blob): Promise<IRemoteFile>;
|
|
28
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { IAuthConfig, IFilePath, IRemoteFile } from '../types';
|
|
2
|
+
import { AuthenticatedDriveBase, IRequestFunction } from './base';
|
|
3
|
+
export interface IWebDavAuthInfo {
|
|
4
|
+
anonymous?: boolean;
|
|
5
|
+
user?: string;
|
|
6
|
+
password?: string;
|
|
7
|
+
serverOptions: {
|
|
8
|
+
baseUrl: string;
|
|
9
|
+
id?: string;
|
|
10
|
+
name?: string;
|
|
11
|
+
avatar?: string;
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
export declare class WebDav extends AuthenticatedDriveBase {
|
|
15
|
+
constructor(authConfig: IAuthConfig, context: Record<string, unknown>);
|
|
16
|
+
initRequest(): IRequestFunction;
|
|
17
|
+
getAccount(): Promise<{
|
|
18
|
+
id: string;
|
|
19
|
+
name: string;
|
|
20
|
+
avatar: string;
|
|
21
|
+
}>;
|
|
22
|
+
private getWebDavPath;
|
|
23
|
+
private getFullUrl;
|
|
24
|
+
mkdir(param: {
|
|
25
|
+
parent?: IFilePath;
|
|
26
|
+
name: string;
|
|
27
|
+
}): Promise<IRemoteFile>;
|
|
28
|
+
private propFind;
|
|
29
|
+
find(param: IFilePath): Promise<IRemoteFile>;
|
|
30
|
+
list(parent?: IFilePath): AsyncGenerator<IRemoteFile[], void, unknown>;
|
|
31
|
+
get(param: IFilePath): Promise<Blob>;
|
|
32
|
+
remove(param: IFilePath): Promise<void>;
|
|
33
|
+
put(param: IFilePath & {
|
|
34
|
+
parent?: IFilePath;
|
|
35
|
+
name?: string;
|
|
36
|
+
}, data: Blob): Promise<IRemoteFile>;
|
|
37
|
+
}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
export interface IServerConfig {
|
|
2
|
+
redirectUrl: string;
|
|
3
|
+
authProviders: Record<string, {
|
|
4
|
+
clientId: string;
|
|
5
|
+
clientSecret: string;
|
|
6
|
+
scope?: string;
|
|
7
|
+
}>;
|
|
8
|
+
}
|
|
9
|
+
export interface IAuthConfig {
|
|
10
|
+
authProvider: 'google' | 'dropbox' | 'microsoft' | 'password';
|
|
11
|
+
user: string;
|
|
12
|
+
password?: string;
|
|
13
|
+
serverOptions?: Record<string, unknown>;
|
|
14
|
+
}
|
|
15
|
+
export interface IDriveConfig {
|
|
16
|
+
driveProvider: 'googledrive' | 'dropbox' | 'onedrive' | 'webdav';
|
|
17
|
+
auth: IAuthConfig;
|
|
18
|
+
}
|
|
19
|
+
export interface IRemoteFile {
|
|
20
|
+
id: string;
|
|
21
|
+
name: string;
|
|
22
|
+
size: number;
|
|
23
|
+
kind: 'file' | 'folder';
|
|
24
|
+
modifiedTime: string;
|
|
25
|
+
}
|
|
26
|
+
export interface IUserInfo {
|
|
27
|
+
id: string;
|
|
28
|
+
name: string;
|
|
29
|
+
avatar?: string;
|
|
30
|
+
}
|
|
31
|
+
export interface IFilePath {
|
|
32
|
+
id?: string;
|
|
33
|
+
path?: string;
|
|
34
|
+
}
|
package/dist/util.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function delay(time: number): Promise<unknown>;
|
package/package.json
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@usync/drive",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"exports": {
|
|
6
|
+
".": {
|
|
7
|
+
"import": "./dist/index.js",
|
|
8
|
+
"types": "./dist/index.d.ts"
|
|
9
|
+
}
|
|
10
|
+
},
|
|
11
|
+
"files": [
|
|
12
|
+
"dist"
|
|
13
|
+
],
|
|
14
|
+
"publishConfig": {
|
|
15
|
+
"access": "public",
|
|
16
|
+
"registry": "https://registry.npmjs.org/"
|
|
17
|
+
},
|
|
18
|
+
"dependencies": {
|
|
19
|
+
"fast-xml-parser": "^5.3.3",
|
|
20
|
+
"@usync/oauth2": "^0.0.1"
|
|
21
|
+
},
|
|
22
|
+
"scripts": {
|
|
23
|
+
"clean": "del-cli dist tsconfig.tsbuildinfo",
|
|
24
|
+
"build:types": "tsc",
|
|
25
|
+
"build:js": "vite build",
|
|
26
|
+
"build": "pnpm clean && pnpm /^build:/"
|
|
27
|
+
}
|
|
28
|
+
}
|