Skip to content

Commit bb4da4f

Browse files
committed
feat: update models
1 parent 0611008 commit bb4da4f

File tree

11 files changed

+117
-41
lines changed

11 files changed

+117
-41
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"private": true,
3-
"version": "1.4.2",
3+
"version": "1.5.0",
44
"type": "module",
55
"scripts": {
66
"build": "rollup -c",

packages/create-gopeed-ext/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "create-gopeed-ext",
3-
"version": "1.4.2",
3+
"version": "1.5.0",
44
"keywords": [
55
"gopeed"
66
],

packages/create-gopeed-ext/templates/webpack/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
2020
"eslint": "^8.51.0",
2121
"eslint-config-prettier": "^9.0.0",
2222
"eslint-plugin-prettier": "^5.0.0",
23-
"gopeed": "^1.4.2",
24-
"gopeed-polyfill-webpack-plugin": "^1.0.5",
23+
"gopeed": "^1.5.0",
24+
"gopeed-polyfill-webpack-plugin": "^1.0.6",
2525
"prettier": "^3.0.3",
2626
"webpack": "^5.75.0",
2727
"webpack-cli": "^5.0.1"
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* eslint-disable @typescript-eslint/no-unused-vars */
22
/* eslint-disable no-unused-vars */
3-
import { ServerInfo } from '@gopeed/types';
3+
import { Result, ServerInfo } from '@gopeed/types';
44
import { Controller, Get, Route, Security } from 'tsoa';
55

66
@Route('/api/v1')
@@ -11,7 +11,7 @@ export class UsersController extends Controller {
1111
*/
1212
@Security('X-Api-Token')
1313
@Get('/info')
14-
public async info(): Promise<ServerInfo> {
15-
return null as unknown as ServerInfo;
14+
public async info(): Promise<Result<ServerInfo>> {
15+
return null as unknown as Result<ServerInfo>;
1616
}
1717
}
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* eslint-disable @typescript-eslint/no-unused-vars */
22
/* eslint-disable no-unused-vars */
3-
import { Request, ResolveResult } from '@gopeed/types';
3+
import { Request, ResolveResult, Result } from '@gopeed/types';
44
import { Body, Controller, Post, Route, Security } from 'tsoa';
55

66
@Route('/api/v1/resolve')
@@ -11,7 +11,7 @@ export class UsersController extends Controller {
1111
*/
1212
@Security('X-Api-Token')
1313
@Post()
14-
public async resolve(@Body() req: Request): Promise<ResolveResult> {
15-
return null as unknown as ResolveResult;
14+
public async resolve(@Body() req: Request): Promise<Result<ResolveResult>> {
15+
return null as unknown as Result<ResolveResult>;
1616
}
1717
}

packages/gopeed-openapi/src/v1/TaskController.ts

Lines changed: 39 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
/* eslint-disable @typescript-eslint/no-unused-vars */
22
/* eslint-disable no-unused-vars */
3-
import { CreateTaskWithRequest, CreateTaskWithResolveResult, Task, TaskStatus, CreateTaskBatch } from '@gopeed/types';
3+
import {
4+
CreateTaskWithRequest,
5+
CreateTaskWithResolveResult,
6+
Task,
7+
TaskStatus,
8+
CreateTaskBatch,
9+
Result,
10+
} from '@gopeed/types';
411
import { Body, Controller, Delete, Get, Path, Post, Put, Query, Route, Security, SuccessResponse } from 'tsoa';
512

613
@Route('/api/v1/tasks')
@@ -13,8 +20,8 @@ export class UsersController extends Controller {
1320
*/
1421
@Security('X-Api-Token')
1522
@Post()
16-
public async createTask(@Body() req: CreateTaskWithResolveResult | CreateTaskWithRequest): Promise<string> {
17-
return null as unknown as string;
23+
public async createTask(@Body() req: CreateTaskWithResolveResult | CreateTaskWithRequest): Promise<Result<string>> {
24+
return null as unknown as Result<string>;
1825
}
1926

2027
/**
@@ -23,8 +30,8 @@ export class UsersController extends Controller {
2330
*/
2431
@Security('X-Api-Token')
2532
@Post('/batch')
26-
public async createTaskBatch(@Body() req: CreateTaskBatch): Promise<string[]> {
27-
return null as unknown as string[];
33+
public async createTaskBatch(@Body() req: CreateTaskBatch): Promise<Result<string[]>> {
34+
return null as unknown as Result<string[]>;
2835
}
2936

3037
/**
@@ -34,8 +41,8 @@ export class UsersController extends Controller {
3441
*/
3542
@Security('X-Api-Token')
3643
@Get('{id}')
37-
public async getTask(@Path() id: string): Promise<Task> {
38-
return null as unknown as Task;
44+
public async getTask(@Path() id: string): Promise<Result<Task>> {
45+
return null as unknown as Result<Task>;
3946
}
4047

4148
/**
@@ -45,8 +52,19 @@ export class UsersController extends Controller {
4552
*/
4653
@Security('X-Api-Token')
4754
@Get()
48-
public async getTasks(@Query() status: TaskStatus[] = []): Promise<Task[]> {
49-
return null as unknown as Task[];
55+
public async getTasks(@Query() status: TaskStatus[] = []): Promise<Result<Task[]>> {
56+
return null as unknown as Result<Task[]>;
57+
}
58+
59+
/**
60+
* Get task download status detail info
61+
* @param id - Task id
62+
* @returns
63+
*/
64+
@Security('X-Api-Token')
65+
@Get('{id}/stats')
66+
public async stats(@Path() id: string): Promise<Result<Task>> {
67+
return null as unknown as Result<Task>;
5068
}
5169

5270
/**
@@ -57,8 +75,8 @@ export class UsersController extends Controller {
5775
@Security('X-Api-Token')
5876
@Put('{id}/pause')
5977
@SuccessResponse(200)
60-
public async pauseTask(@Path() id: string): Promise<void> {
61-
return null as unknown as void;
78+
public async pauseTask(@Path() id: string): Promise<Result<void>> {
79+
return null as unknown as Result<void>;
6280
}
6381

6482
/**
@@ -69,8 +87,8 @@ export class UsersController extends Controller {
6987
@Security('X-Api-Token')
7088
@Put('{id}/continue')
7189
@SuccessResponse(200)
72-
public async continueTask(@Path() id: string): Promise<void> {
73-
return null as unknown as void;
90+
public async continueTask(@Path() id: string): Promise<Result<void>> {
91+
return null as unknown as Result<void>;
7492
}
7593

7694
/**
@@ -80,8 +98,8 @@ export class UsersController extends Controller {
8098
@Security('X-Api-Token')
8199
@Put('pause')
82100
@SuccessResponse(200)
83-
public async pauseAllTasks(): Promise<void> {
84-
return;
101+
public async pauseAllTasks(): Promise<Result<void>> {
102+
return null as unknown as Result<void>;
85103
}
86104

87105
/**
@@ -91,8 +109,8 @@ export class UsersController extends Controller {
91109
@Security('X-Api-Token')
92110
@Put('continue')
93111
@SuccessResponse(200)
94-
public async continueAllTasks(): Promise<void> {
95-
return;
112+
public async continueAllTasks(): Promise<Result<void>> {
113+
return null as unknown as Result<void>;
96114
}
97115

98116
/**
@@ -104,8 +122,8 @@ export class UsersController extends Controller {
104122
@Security('X-Api-Token')
105123
@Delete('{id}')
106124
@SuccessResponse(200)
107-
public async deleteTask(@Path() id: string, @Query() force = false): Promise<void> {
108-
return;
125+
public async deleteTask(@Path() id: string, @Query() force = false): Promise<Result<void>> {
126+
return null as unknown as Result<void>;
109127
}
110128

111129
/**
@@ -117,7 +135,7 @@ export class UsersController extends Controller {
117135
@Security('X-Api-Token')
118136
@Delete()
119137
@SuccessResponse(200)
120-
public async deleteTasks(@Query() status: TaskStatus[] = [], @Query() force = false): Promise<void> {
121-
return;
138+
public async deleteTasks(@Query() status: TaskStatus[] = [], @Query() force = false): Promise<Result<void>> {
139+
return null as unknown as Result<void>;
122140
}
123141
}

packages/gopeed-rest/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@gopeed/rest",
3-
"version": "1.4.2",
3+
"version": "1.5.0",
44
"description": "",
55
"main": "dist/index.js",
66
"exports": {

packages/gopeed-rest/src/index.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import type {
2+
Result,
23
Request,
34
CreateTaskWithRequest,
45
CreateTaskWithResolveResult,
@@ -12,12 +13,6 @@ interface ClientOptions {
1213
token: string;
1314
}
1415

15-
interface Result<T> {
16-
code: number;
17-
msg: string;
18-
data: T;
19-
}
20-
2116
class ApiError extends Error {
2217
code: number;
2318
msg: string;

packages/gopeed-types/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@gopeed/types",
3-
"version": "1.4.2",
3+
"version": "1.5.0",
44
"description": "",
55
"main": "dist/index.js",
66
"exports": {

packages/gopeed-types/src/index.ts

Lines changed: 64 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,24 @@
11
export type HttpMethod = 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH' | 'HEAD' | 'OPTIONS' | 'CONNECT' | 'TRACE';
22
export type HttpHeader = { [key: string]: string };
33

4+
/**
5+
* REST API result
6+
*/
7+
export interface Result<T> {
8+
/**
9+
* The response code, `0` means success, other values means error.
10+
*/
11+
code: number;
12+
/**
13+
* The response message, if `code` != `0`, this field will contain error message.
14+
*/
15+
msg: string;
16+
/**
17+
* The response data, if `code` == `0`, this field will contain response data.
18+
*/
19+
data: T;
20+
}
21+
422
/**
523
* Server info
624
*/
@@ -119,7 +137,6 @@ export interface FileInfo {
119137
* File size(byte)
120138
*/
121139
size: number;
122-
123140
/**
124141
* Specify the request for this file
125142
*/
@@ -176,6 +193,8 @@ export interface Options {
176193
extra?: HttpOptExtra;
177194
}
178195

196+
export type Protocol = 'http' | 'bt';
197+
179198
export type TaskStatus = 'ready' | 'running' | 'pause' | 'wait' | 'error' | 'done';
180199

181200
export interface TaskProgress {
@@ -191,13 +210,25 @@ export interface TaskProgress {
191210
* Downloaded size(byte)
192211
*/
193212
downloaded: number;
213+
/**
214+
* Uploaded speed(bytes/s)
215+
*/
216+
uploadSpeed: number;
217+
/**
218+
* Uploaded size(bytes)
219+
*/
220+
uploaded: number;
194221
}
195222

196223
export interface Task {
197224
/**
198225
* Task id
199226
*/
200227
id: string;
228+
/**
229+
* Protocol type
230+
*/
231+
protocol: Protocol;
201232
/**
202233
* Task metadata
203234
*/
@@ -212,6 +243,10 @@ export interface Task {
212243
* @example "running"
213244
*/
214245
status: TaskStatus;
246+
/**
247+
* Task is uploading
248+
*/
249+
uploading: boolean;
215250
/**
216251
* Task progress
217252
*/
@@ -232,6 +267,34 @@ export interface Task {
232267
updatedAt: string;
233268
}
234269

270+
export interface TaskBtStats {
271+
/**
272+
* Total peers
273+
*/
274+
totalPeers: number;
275+
/**
276+
* Active peers
277+
*/
278+
activePeers: number;
279+
/**
280+
* Connected seeders
281+
*/
282+
connectedSeeders: number;
283+
/**
284+
* Total seed bytes
285+
*/
286+
seedBytes: number;
287+
/**
288+
* Seed ratio
289+
* @example 0.1
290+
*/
291+
seedRatio: number;
292+
/**
293+
* Total seed time(s)
294+
*/
295+
seedTime: number;
296+
}
297+
235298
export interface CreateTaskWithResolveResult {
236299
/**
237300
* Resolved id, from resolved result

0 commit comments

Comments
 (0)