@nger/fk-upload 1.0.125 → 1.0.126
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.
@@ -125,73 +125,83 @@ let FkService = class FkService {
|
|
125
125
|
return size;
|
126
126
|
}
|
127
127
|
async uploadFile(task) {
|
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
|
-
|
128
|
+
const upload = async () => {
|
129
|
+
const info = await this.getUploadInfo(task.loginId, task.filename, task.fileMd5, task.total);
|
130
|
+
task.cookies = info.cookies;
|
131
|
+
task.splitSize = info.splitSize;
|
132
|
+
task.start = info.uploadedSize;
|
133
|
+
task.uploadUrl = info.uploadUrl;
|
134
|
+
task.index = Math.ceil(info.uploadedSize / info.splitSize);
|
135
|
+
let complete = false;
|
136
|
+
const max = task.total - 1;
|
137
|
+
let index = task.index || 0;
|
138
|
+
let uploadResult;
|
139
|
+
do {
|
140
|
+
let start = index * task.splitSize;
|
141
|
+
let _end = start + task.splitSize - 1;
|
142
|
+
let end = _end > max ? max : _end;
|
143
|
+
if (end >= max) {
|
144
|
+
complete = true;
|
145
|
+
}
|
146
|
+
const fileStream = (0, fs_extra_1.createReadStream)(task.path, { start: start, end: end });
|
147
|
+
const formdata = new form_data_1.default();
|
148
|
+
formdata.append('ctrl', fileStream);
|
149
|
+
formdata.append('isFreeVer', this.encodeURIComponent(false));
|
150
|
+
formdata.append('aid', this.encodeURIComponent(task.aid));
|
151
|
+
formdata.append('folderId', this.encodeURIComponent(task.folderId));
|
152
|
+
formdata.append('fileName', task.filename);
|
153
|
+
formdata.append(`totalSize`, this.encodeURIComponent(task.total));
|
154
|
+
formdata.append(`fileMd5`, task.fileMd5);
|
155
|
+
formdata.append('index', this.encodeURIComponent(index));
|
156
|
+
formdata.append('chunkSize', this.encodeURIComponent(task.splitSize));
|
157
|
+
formdata.append('totalChunks', this.encodeURIComponent(task.totalChunks));
|
158
|
+
formdata.append(`complete`, this.encodeURIComponent(complete));
|
159
|
+
const bssInfo = {
|
160
|
+
fromSite: true, siteId: 0, groupId: 0, fileSizeLimit: 1024
|
161
|
+
};
|
162
|
+
formdata.append('bssInfo', JSON.stringify(bssInfo));
|
163
|
+
const headers = formdata.getHeaders();
|
164
|
+
uploadResult = await axios_1.default.post(task.uploadUrl, formdata, {
|
165
|
+
headers: {
|
166
|
+
...headers,
|
167
|
+
Cookie: task.cookies
|
168
|
+
},
|
169
|
+
timeout: 8000
|
170
|
+
}).then(res => {
|
171
|
+
return res.data;
|
172
|
+
}).catch((e) => {
|
173
|
+
console.log(`upload error`, e.message);
|
174
|
+
return upload();
|
175
|
+
});
|
176
|
+
if (uploadResult.code !== 200) {
|
177
|
+
if (uploadResult.data) {
|
178
|
+
const data = uploadResult.data;
|
179
|
+
if (data.limit) {
|
180
|
+
// to big
|
181
|
+
throw new Error(`to big`);
|
182
|
+
}
|
174
183
|
}
|
184
|
+
throw new Error(`${task.filename}--${uploadResult.msg}`);
|
175
185
|
}
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
+
console.log(`upload ----- `, { index, max, start, end });
|
187
|
+
if (uploadResult) {
|
188
|
+
const data = uploadResult.data;
|
189
|
+
const downUrl = data.path;
|
190
|
+
if (downUrl) {
|
191
|
+
if (downUrl.startsWith('https://site-upload')) {
|
192
|
+
console.log(`upload fail`);
|
193
|
+
throw new Error(`need re bind`);
|
194
|
+
}
|
195
|
+
const fullUrl = downUrl.startsWith('http') ? downUrl : `https:` + downUrl;
|
196
|
+
task.uploadUrl = fullUrl;
|
186
197
|
}
|
187
|
-
const fullUrl = downUrl.startsWith('http') ? downUrl : `https:` + downUrl;
|
188
|
-
task.uploadUrl = fullUrl;
|
189
198
|
}
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
199
|
+
index = index + 1;
|
200
|
+
} while (!complete);
|
201
|
+
return uploadResult;
|
202
|
+
};
|
203
|
+
const result = await upload();
|
204
|
+
console.log(`upload result: -----> `, result);
|
195
205
|
// upload complete
|
196
206
|
axios_1.default.post(`https://smr00.vip.webportal.top/ajax/advanceUpload.jsp?cmd=_report&_TOKEN=${task.token}`, this.encodeURIComponent({
|
197
207
|
type: 1,
|