Skip to content

Commit

Permalink
fix: task stats api
Browse files Browse the repository at this point in the history
  • Loading branch information
monkeyWie committed Aug 20, 2024
1 parent bb4da4f commit 873c8a7
Show file tree
Hide file tree
Showing 9 changed files with 46 additions and 12 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.5.0",
"version": "1.5.1",
"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.5.0",
"version": "1.5.1",
"keywords": [
"gopeed"
],
Expand Down
2 changes: 1 addition & 1 deletion packages/create-gopeed-ext/templates/webpack/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"eslint": "^8.51.0",
"eslint-config-prettier": "^9.0.0",
"eslint-plugin-prettier": "^5.0.0",
"gopeed": "^1.5.0",
"gopeed": "^1.5.1",
"gopeed-polyfill-webpack-plugin": "^1.0.6",
"prettier": "^3.0.3",
"webpack": "^5.75.0",
Expand Down
7 changes: 4 additions & 3 deletions packages/gopeed-openapi/src/v1/TaskController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
TaskStatus,
CreateTaskBatch,
Result,
TaskStats,
} from '@gopeed/types';
import { Body, Controller, Delete, Get, Path, Post, Put, Query, Route, Security, SuccessResponse } from 'tsoa';

Expand Down Expand Up @@ -57,14 +58,14 @@ export class UsersController extends Controller {
}

/**
* Get task download status detail info
* Get task stats
* @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>;
public async stats(@Path() id: string): Promise<Result<TaskStats>> {
return null as unknown as Result<TaskStats>;
}

/**
Expand Down
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.5.0",
"version": "1.5.1",
"description": "",
"main": "dist/index.js",
"exports": {
Expand Down
25 changes: 24 additions & 1 deletion packages/gopeed-rest/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import type {
Result,
Request,
ResolveResult,
CreateTaskWithRequest,
CreateTaskWithResolveResult,
ResolveResult,
CreateTaskBatch,
Task,
TaskStatus,
TaskBtStats,
TaskStats,
} from '@gopeed/types';

interface ClientOptions {
Expand Down Expand Up @@ -53,6 +56,17 @@ class Client {
});
}

/**
* Create a batch of download tasks
* @param request - The request to create a batch of download tasks
* @returns
*/
public async createTaskBatch(request: CreateTaskBatch): Promise<string[]> {
return this.doRequest<string[]>('POST', '/api/v1/tasks/batch', {
data: request,
});
}

/**
* Get task info
* @param id - Task id
Expand All @@ -75,6 +89,15 @@ class Client {
});
}

/**
* Get task stats
* @param id - Task id
* @returns
*/
public async getTaskStats(id: string): Promise<TaskStats> {
return this.doRequest<TaskBtStats>('GET', `/api/v1/tasks/${id}/stats`);
}

/**
* Pause a task
* @param id - Task id
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.5.0",
"version": "1.5.1",
"description": "",
"main": "dist/index.js",
"exports": {
Expand Down
14 changes: 12 additions & 2 deletions packages/gopeed-types/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ export interface BtReqExtra {
trackers?: string[];
}

export type ReqExtra = HttpReqExtra | BtReqExtra;

/**
* HTTP download extra options
* @example {
Expand All @@ -93,8 +95,14 @@ export interface HttpOptExtra {
* Concurrent connections
*/
connections?: number;
/**
* When task download complete, and it is a .torrent file, it will be auto create a new task for the torrent file
*/
autoTorrent?: boolean;
}

export type OptExtra = HttpOptExtra;

/**
* Download request
* @example {
Expand All @@ -109,7 +117,7 @@ export interface Request {
/**
* Extra request options
*/
extra?: HttpReqExtra | BtReqExtra;
extra?: ReqExtra;
/**
* Request labels
*/
Expand Down Expand Up @@ -190,7 +198,7 @@ export interface Options {
/**
* Download extra options
*/
extra?: HttpOptExtra;
extra?: OptExtra;
}

export type Protocol = 'http' | 'bt';
Expand Down Expand Up @@ -295,6 +303,8 @@ export interface TaskBtStats {
seedTime: number;
}

export type TaskStats = TaskBtStats;

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.5.0",
"version": "1.5.1",
"description": "",
"main": "index.js",
"type": "module",
Expand Down

0 comments on commit 873c8a7

Please sign in to comment.