Skip to content

Commit

Permalink
feat: update models
Browse files Browse the repository at this point in the history
  • Loading branch information
monkeyWie committed Aug 20, 2024
1 parent 0611008 commit bb4da4f
Show file tree
Hide file tree
Showing 11 changed files with 117 additions and 41 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"private": true,
"version": "1.4.2",
"version": "1.5.0",
"type": "module",
"scripts": {
"build": "rollup -c",
Expand Down
2 changes: 1 addition & 1 deletion packages/create-gopeed-ext/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "create-gopeed-ext",
"version": "1.4.2",
"version": "1.5.0",
"keywords": [
"gopeed"
],
Expand Down
4 changes: 2 additions & 2 deletions packages/create-gopeed-ext/templates/webpack/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
"eslint": "^8.51.0",
"eslint-config-prettier": "^9.0.0",
"eslint-plugin-prettier": "^5.0.0",
"gopeed": "^1.4.2",
"gopeed-polyfill-webpack-plugin": "^1.0.5",
"gopeed": "^1.5.0",
"gopeed-polyfill-webpack-plugin": "^1.0.6",
"prettier": "^3.0.3",
"webpack": "^5.75.0",
"webpack-cli": "^5.0.1"
Expand Down
6 changes: 3 additions & 3 deletions packages/gopeed-openapi/src/v1/IndexController.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable @typescript-eslint/no-unused-vars */
/* eslint-disable no-unused-vars */
import { ServerInfo } from '@gopeed/types';
import { Result, ServerInfo } from '@gopeed/types';
import { Controller, Get, Route, Security } from 'tsoa';

@Route('/api/v1')
Expand All @@ -11,7 +11,7 @@ export class UsersController extends Controller {
*/
@Security('X-Api-Token')
@Get('/info')
public async info(): Promise<ServerInfo> {
return null as unknown as ServerInfo;
public async info(): Promise<Result<ServerInfo>> {
return null as unknown as Result<ServerInfo>;
}
}
6 changes: 3 additions & 3 deletions packages/gopeed-openapi/src/v1/ResolveController.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable @typescript-eslint/no-unused-vars */
/* eslint-disable no-unused-vars */
import { Request, ResolveResult } from '@gopeed/types';
import { Request, ResolveResult, Result } from '@gopeed/types';
import { Body, Controller, Post, Route, Security } from 'tsoa';

@Route('/api/v1/resolve')
Expand All @@ -11,7 +11,7 @@ export class UsersController extends Controller {
*/
@Security('X-Api-Token')
@Post()
public async resolve(@Body() req: Request): Promise<ResolveResult> {
return null as unknown as ResolveResult;
public async resolve(@Body() req: Request): Promise<Result<ResolveResult>> {
return null as unknown as Result<ResolveResult>;
}
}
60 changes: 39 additions & 21 deletions packages/gopeed-openapi/src/v1/TaskController.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
/* eslint-disable @typescript-eslint/no-unused-vars */
/* eslint-disable no-unused-vars */
import { CreateTaskWithRequest, CreateTaskWithResolveResult, Task, TaskStatus, CreateTaskBatch } from '@gopeed/types';
import {
CreateTaskWithRequest,
CreateTaskWithResolveResult,
Task,
TaskStatus,
CreateTaskBatch,
Result,
} from '@gopeed/types';
import { Body, Controller, Delete, Get, Path, Post, Put, Query, Route, Security, SuccessResponse } from 'tsoa';

@Route('/api/v1/tasks')
Expand All @@ -13,8 +20,8 @@ export class UsersController extends Controller {
*/
@Security('X-Api-Token')
@Post()
public async createTask(@Body() req: CreateTaskWithResolveResult | CreateTaskWithRequest): Promise<string> {
return null as unknown as string;
public async createTask(@Body() req: CreateTaskWithResolveResult | CreateTaskWithRequest): Promise<Result<string>> {
return null as unknown as Result<string>;
}

/**
Expand All @@ -23,8 +30,8 @@ export class UsersController extends Controller {
*/
@Security('X-Api-Token')
@Post('/batch')
public async createTaskBatch(@Body() req: CreateTaskBatch): Promise<string[]> {
return null as unknown as string[];
public async createTaskBatch(@Body() req: CreateTaskBatch): Promise<Result<string[]>> {
return null as unknown as Result<string[]>;
}

/**
Expand All @@ -34,8 +41,8 @@ export class UsersController extends Controller {
*/
@Security('X-Api-Token')
@Get('{id}')
public async getTask(@Path() id: string): Promise<Task> {
return null as unknown as Task;
public async getTask(@Path() id: string): Promise<Result<Task>> {
return null as unknown as Result<Task>;
}

/**
Expand All @@ -45,8 +52,19 @@ export class UsersController extends Controller {
*/
@Security('X-Api-Token')
@Get()
public async getTasks(@Query() status: TaskStatus[] = []): Promise<Task[]> {
return null as unknown as Task[];
public async getTasks(@Query() status: TaskStatus[] = []): Promise<Result<Task[]>> {
return null as unknown as Result<Task[]>;
}

/**
* Get task download status detail info
* @param id - Task id
* @returns
*/
@Security('X-Api-Token')
@Get('{id}/stats')
public async stats(@Path() id: string): Promise<Result<Task>> {
return null as unknown as Result<Task>;
}

/**
Expand All @@ -57,8 +75,8 @@ export class UsersController extends Controller {
@Security('X-Api-Token')
@Put('{id}/pause')
@SuccessResponse(200)
public async pauseTask(@Path() id: string): Promise<void> {
return null as unknown as void;
public async pauseTask(@Path() id: string): Promise<Result<void>> {
return null as unknown as Result<void>;
}

/**
Expand All @@ -69,8 +87,8 @@ export class UsersController extends Controller {
@Security('X-Api-Token')
@Put('{id}/continue')
@SuccessResponse(200)
public async continueTask(@Path() id: string): Promise<void> {
return null as unknown as void;
public async continueTask(@Path() id: string): Promise<Result<void>> {
return null as unknown as Result<void>;
}

/**
Expand All @@ -80,8 +98,8 @@ export class UsersController extends Controller {
@Security('X-Api-Token')
@Put('pause')
@SuccessResponse(200)
public async pauseAllTasks(): Promise<void> {
return;
public async pauseAllTasks(): Promise<Result<void>> {
return null as unknown as Result<void>;
}

/**
Expand All @@ -91,8 +109,8 @@ export class UsersController extends Controller {
@Security('X-Api-Token')
@Put('continue')
@SuccessResponse(200)
public async continueAllTasks(): Promise<void> {
return;
public async continueAllTasks(): Promise<Result<void>> {
return null as unknown as Result<void>;
}

/**
Expand All @@ -104,8 +122,8 @@ export class UsersController extends Controller {
@Security('X-Api-Token')
@Delete('{id}')
@SuccessResponse(200)
public async deleteTask(@Path() id: string, @Query() force = false): Promise<void> {
return;
public async deleteTask(@Path() id: string, @Query() force = false): Promise<Result<void>> {
return null as unknown as Result<void>;
}

/**
Expand All @@ -117,7 +135,7 @@ export class UsersController extends Controller {
@Security('X-Api-Token')
@Delete()
@SuccessResponse(200)
public async deleteTasks(@Query() status: TaskStatus[] = [], @Query() force = false): Promise<void> {
return;
public async deleteTasks(@Query() status: TaskStatus[] = [], @Query() force = false): Promise<Result<void>> {
return null as unknown as Result<void>;
}
}
2 changes: 1 addition & 1 deletion packages/gopeed-rest/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@gopeed/rest",
"version": "1.4.2",
"version": "1.5.0",
"description": "",
"main": "dist/index.js",
"exports": {
Expand Down
7 changes: 1 addition & 6 deletions packages/gopeed-rest/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type {
Result,
Request,
CreateTaskWithRequest,
CreateTaskWithResolveResult,
Expand All @@ -12,12 +13,6 @@ interface ClientOptions {
token: string;
}

interface Result<T> {
code: number;
msg: string;
data: T;
}

class ApiError extends Error {
code: number;
msg: string;
Expand Down
2 changes: 1 addition & 1 deletion packages/gopeed-types/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@gopeed/types",
"version": "1.4.2",
"version": "1.5.0",
"description": "",
"main": "dist/index.js",
"exports": {
Expand Down
65 changes: 64 additions & 1 deletion packages/gopeed-types/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,24 @@
export type HttpMethod = 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH' | 'HEAD' | 'OPTIONS' | 'CONNECT' | 'TRACE';
export type HttpHeader = { [key: string]: string };

/**
* REST API result
*/
export interface Result<T> {
/**
* The response code, `0` means success, other values means error.
*/
code: number;
/**
* The response message, if `code` != `0`, this field will contain error message.
*/
msg: string;
/**
* The response data, if `code` == `0`, this field will contain response data.
*/
data: T;
}

/**
* Server info
*/
Expand Down Expand Up @@ -119,7 +137,6 @@ export interface FileInfo {
* File size(byte)
*/
size: number;

/**
* Specify the request for this file
*/
Expand Down Expand Up @@ -176,6 +193,8 @@ export interface Options {
extra?: HttpOptExtra;
}

export type Protocol = 'http' | 'bt';

export type TaskStatus = 'ready' | 'running' | 'pause' | 'wait' | 'error' | 'done';

export interface TaskProgress {
Expand All @@ -191,13 +210,25 @@ export interface TaskProgress {
* Downloaded size(byte)
*/
downloaded: number;
/**
* Uploaded speed(bytes/s)
*/
uploadSpeed: number;
/**
* Uploaded size(bytes)
*/
uploaded: number;
}

export interface Task {
/**
* Task id
*/
id: string;
/**
* Protocol type
*/
protocol: Protocol;
/**
* Task metadata
*/
Expand All @@ -212,6 +243,10 @@ export interface Task {
* @example "running"
*/
status: TaskStatus;
/**
* Task is uploading
*/
uploading: boolean;
/**
* Task progress
*/
Expand All @@ -232,6 +267,34 @@ export interface Task {
updatedAt: string;
}

export interface TaskBtStats {
/**
* Total peers
*/
totalPeers: number;
/**
* Active peers
*/
activePeers: number;
/**
* Connected seeders
*/
connectedSeeders: number;
/**
* Total seed bytes
*/
seedBytes: number;
/**
* Seed ratio
* @example 0.1
*/
seedRatio: number;
/**
* Total seed time(s)
*/
seedTime: number;
}

export interface CreateTaskWithResolveResult {
/**
* Resolved id, from resolved result
Expand Down
2 changes: 1 addition & 1 deletion packages/gopeed/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "gopeed",
"version": "1.4.2",
"version": "1.5.0",
"description": "",
"main": "index.js",
"type": "module",
Expand Down

0 comments on commit bb4da4f

Please sign in to comment.