fsd-vod 0.7.2 → 0.10.0
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 +1 -1
- package/index.d.ts +37 -0
- package/lib/index.js +24 -18
- package/package.json +7 -7
- package/tsconfig.json +0 -29
package/README.md
CHANGED
package/index.d.ts
CHANGED
|
@@ -88,7 +88,44 @@ export interface PlayInfoResult {
|
|
|
88
88
|
};
|
|
89
89
|
}
|
|
90
90
|
|
|
91
|
+
export interface UploadToken {
|
|
92
|
+
auth: {
|
|
93
|
+
accessKeyId: string;
|
|
94
|
+
accessKeySecret: string;
|
|
95
|
+
stsToken: string;
|
|
96
|
+
bucket: string;
|
|
97
|
+
endpoint: string;
|
|
98
|
+
};
|
|
99
|
+
path: string;
|
|
100
|
+
expiration: number;
|
|
101
|
+
callback?: any;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
export interface UploadTokenWithAutoRefresh {
|
|
105
|
+
auth: {
|
|
106
|
+
accessKeyId: string;
|
|
107
|
+
accessKeySecret: string;
|
|
108
|
+
stsToken: string;
|
|
109
|
+
bucket: string;
|
|
110
|
+
endpoint: string;
|
|
111
|
+
refreshSTSToken: () => Promise<{
|
|
112
|
+
accessKeyId: string;
|
|
113
|
+
accessKeySecret: string;
|
|
114
|
+
stsToken: string;
|
|
115
|
+
}>;
|
|
116
|
+
};
|
|
117
|
+
path: string;
|
|
118
|
+
expiration: number;
|
|
119
|
+
callback?: any;
|
|
120
|
+
}
|
|
121
|
+
|
|
91
122
|
export default class VODAdpter extends Adapter<VODAdapterOptions> {
|
|
123
|
+
createUploadToken: (videoId: string, meta?: any) => Promise<UploadToken>;
|
|
124
|
+
createUploadTokenWithAutoRefresh: (
|
|
125
|
+
videoId: string,
|
|
126
|
+
meta?: any
|
|
127
|
+
) => Promise<UploadTokenWithAutoRefresh>;
|
|
128
|
+
|
|
92
129
|
getVideoInfo(videoId: string): Promise<null | VideoInfo>;
|
|
93
130
|
getMezzanineInfo(videoId: string, options?: any): Promise<null | MezzanineInfo>;
|
|
94
131
|
getPlayInfo(videoId: string, options?: any): Promise<null | PlayInfoResult>;
|
package/lib/index.js
CHANGED
|
@@ -4,7 +4,6 @@ const OSS = require("ali-oss");
|
|
|
4
4
|
const LRUCache = require("lru-cache");
|
|
5
5
|
const Debugger = require("debug");
|
|
6
6
|
const RPC = require("@alicloud/pop-core");
|
|
7
|
-
const url_1 = require("url");
|
|
8
7
|
const stream_1 = require("stream");
|
|
9
8
|
const akita_1 = require("akita");
|
|
10
9
|
const debug = Debugger('fsd-vod');
|
|
@@ -106,6 +105,17 @@ class VODAdapter {
|
|
|
106
105
|
}
|
|
107
106
|
return token;
|
|
108
107
|
};
|
|
108
|
+
this.createUploadTokenWithAutoRefresh = async (videoId, meta) => {
|
|
109
|
+
let token = await this.createUploadToken(videoId, meta);
|
|
110
|
+
let auth = token.auth;
|
|
111
|
+
auth = Object.assign({}, auth, {
|
|
112
|
+
refreshSTSToken: async () => {
|
|
113
|
+
let t = await this.createUploadToken(videoId, meta);
|
|
114
|
+
return t.auth;
|
|
115
|
+
}
|
|
116
|
+
});
|
|
117
|
+
return Object.assign({}, token, { auth });
|
|
118
|
+
};
|
|
109
119
|
}
|
|
110
120
|
async getVideoInfo(videoId) {
|
|
111
121
|
if (videoId[0] === '/')
|
|
@@ -152,7 +162,7 @@ class VODAdapter {
|
|
|
152
162
|
}
|
|
153
163
|
async append(videoId, data) {
|
|
154
164
|
debug('append %s', videoId);
|
|
155
|
-
let token = await this.
|
|
165
|
+
let token = await this.createUploadTokenWithAutoRefresh(videoId);
|
|
156
166
|
let oss = new OSS(token.auth);
|
|
157
167
|
if (typeof data === 'string') {
|
|
158
168
|
data = Buffer.from(data);
|
|
@@ -184,7 +194,7 @@ class VODAdapter {
|
|
|
184
194
|
debug('createWriteStream %s', videoId);
|
|
185
195
|
if (options === null || options === void 0 ? void 0 : options.start)
|
|
186
196
|
throw new Error('fsd-vod read stream does not support start options');
|
|
187
|
-
let token = await this.
|
|
197
|
+
let token = await this.createUploadTokenWithAutoRefresh(videoId);
|
|
188
198
|
let oss = new OSS(token.auth);
|
|
189
199
|
let stream = new stream_1.PassThrough();
|
|
190
200
|
stream.promise = oss.putStream(token.path.substr(1), stream);
|
|
@@ -192,25 +202,24 @@ class VODAdapter {
|
|
|
192
202
|
}
|
|
193
203
|
async initMultipartUpload(videoId, partCount) {
|
|
194
204
|
debug('initMultipartUpload %s, partCount: %d', videoId, partCount);
|
|
195
|
-
let token = await this.
|
|
205
|
+
let token = await this.createUploadTokenWithAutoRefresh(videoId);
|
|
196
206
|
let oss = new OSS(token.auth);
|
|
197
|
-
let res = await oss.initMultipartUpload(token.path.
|
|
207
|
+
let res = await oss.initMultipartUpload(token.path.substring(1));
|
|
198
208
|
let { uploadId } = res;
|
|
199
209
|
let files = [];
|
|
200
210
|
for (let i = 1; i <= partCount; i += 1) {
|
|
201
|
-
files.push(`task://${uploadId}
|
|
211
|
+
files.push(`task://${uploadId}?${i}`);
|
|
202
212
|
}
|
|
203
213
|
return files;
|
|
204
214
|
}
|
|
205
215
|
async writePart(videoId, partTask, data, size) {
|
|
206
216
|
debug('writePart %s, task: %s', videoId, partTask);
|
|
207
|
-
|
|
217
|
+
if (!partTask.startsWith('task://'))
|
|
218
|
+
throw new Error('Invalid part task id');
|
|
219
|
+
let token = await this.createUploadTokenWithAutoRefresh(videoId);
|
|
208
220
|
let oss = new OSS(token.auth);
|
|
209
|
-
let
|
|
210
|
-
|
|
211
|
-
throw new Error('Invalid part pathname');
|
|
212
|
-
let uploadId = (info.hostname || '').toUpperCase();
|
|
213
|
-
let res = await oss._uploadPart(token.path.substr(1), uploadId, info.search.substr(1), {
|
|
221
|
+
let [uploadId, no] = partTask.replace('task://', '').split('?');
|
|
222
|
+
let res = await oss._uploadPart(token.path.substring(1), uploadId, parseInt(no), {
|
|
214
223
|
stream: data,
|
|
215
224
|
size
|
|
216
225
|
});
|
|
@@ -219,18 +228,15 @@ class VODAdapter {
|
|
|
219
228
|
}
|
|
220
229
|
async completeMultipartUpload(videoId, parts) {
|
|
221
230
|
debug('completeMultipartUpload %s', videoId);
|
|
222
|
-
let token = await this.
|
|
231
|
+
let token = await this.createUploadTokenWithAutoRefresh(videoId);
|
|
223
232
|
let oss = new OSS(token.auth);
|
|
224
|
-
let
|
|
225
|
-
if (!info.pathname || info.pathname !== token.path)
|
|
226
|
-
throw new Error('Invalid part pathname');
|
|
227
|
-
let uploadId = (info.hostname || '').toUpperCase();
|
|
233
|
+
let uploadId = parts[0].replace('part://', '').split('?')[0];
|
|
228
234
|
debug('update id: %s, target: %s', uploadId, token.path);
|
|
229
235
|
let datas = parts.map((item, key) => ({
|
|
230
236
|
etag: item.split('#')[1],
|
|
231
237
|
number: key + 1
|
|
232
238
|
}));
|
|
233
|
-
await oss.completeMultipartUpload(token.path.
|
|
239
|
+
await oss.completeMultipartUpload(token.path.substring(1), uploadId, datas);
|
|
234
240
|
}
|
|
235
241
|
async createUrl(videoId, options) {
|
|
236
242
|
debug('createUrl %s', videoId);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "fsd-vod",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.10.0",
|
|
4
4
|
"description": "Aliyun OSS adapter for fsd",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "index.d.ts",
|
|
@@ -8,15 +8,15 @@
|
|
|
8
8
|
"build": "tsc",
|
|
9
9
|
"prepublish": "npm run build"
|
|
10
10
|
},
|
|
11
|
-
"repository": "https://github.com/
|
|
12
|
-
"author": "Liang <liang@
|
|
11
|
+
"repository": "https://github.com/liangxingchen/fsd/tree/master/packages/fsd-vod",
|
|
12
|
+
"author": "Liang <liang@miaomo.cc> (https://github.com/liangxingchen)",
|
|
13
13
|
"license": "MIT",
|
|
14
14
|
"dependencies": {
|
|
15
15
|
"@alicloud/pop-core": "^1.7.10",
|
|
16
|
-
"akita": "^0.
|
|
17
|
-
"ali-oss": "^6.
|
|
18
|
-
"debug": "^4.3.
|
|
16
|
+
"akita": "^0.12.1",
|
|
17
|
+
"ali-oss": "^6.17.1",
|
|
18
|
+
"debug": "^4.3.4",
|
|
19
19
|
"lru-cache": "^6.0.0"
|
|
20
20
|
},
|
|
21
|
-
"gitHead": "
|
|
21
|
+
"gitHead": "9820fd7263b6791a38e5568396bfac0f2d3e37e9"
|
|
22
22
|
}
|
package/tsconfig.json
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compilerOptions": {
|
|
3
|
-
"module": "commonjs",
|
|
4
|
-
"allowSyntheticDefaultImports": true,
|
|
5
|
-
"noImplicitAny": true,
|
|
6
|
-
"removeComments": true,
|
|
7
|
-
"preserveConstEnums": true,
|
|
8
|
-
"outDir": "lib",
|
|
9
|
-
"moduleResolution": "node",
|
|
10
|
-
"baseUrl": ".",
|
|
11
|
-
"paths": {
|
|
12
|
-
"*": [
|
|
13
|
-
"../../packages/*",
|
|
14
|
-
"../../typings/*"
|
|
15
|
-
]
|
|
16
|
-
},
|
|
17
|
-
"target": "ES2017",
|
|
18
|
-
"lib": [
|
|
19
|
-
"es7",
|
|
20
|
-
"dom"
|
|
21
|
-
]
|
|
22
|
-
},
|
|
23
|
-
"include": [
|
|
24
|
-
"src/**/*"
|
|
25
|
-
],
|
|
26
|
-
"exclude": [
|
|
27
|
-
"node_modules"
|
|
28
|
-
]
|
|
29
|
-
}
|