diff --git a/.gitignore b/.gitignore index 3af521e..29d5dcf 100644 --- a/.gitignore +++ b/.gitignore @@ -130,4 +130,6 @@ dist .pnp.* # Typedoc output -docs \ No newline at end of file +docs + +swagger.json \ No newline at end of file diff --git a/package.json b/package.json index 87c6d46..d0a1e95 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "private": true, - "version": "1.0.5", + "version": "1.0.6", "packageManager": "pnpm@8.6.1", "type": "module", "scripts": { diff --git a/packages/create-gopeed-ext/package.json b/packages/create-gopeed-ext/package.json index 668ef6a..724049f 100644 --- a/packages/create-gopeed-ext/package.json +++ b/packages/create-gopeed-ext/package.json @@ -1,6 +1,6 @@ { "name": "create-gopeed-ext", - "version": "1.0.5", + "version": "1.0.6", "keywords": [ "gopeed" ], diff --git a/packages/create-gopeed-ext/templates/webpack/package.json b/packages/create-gopeed-ext/templates/webpack/package.json index 9d1230e..31ad0de 100644 --- a/packages/create-gopeed-ext/templates/webpack/package.json +++ b/packages/create-gopeed-ext/templates/webpack/package.json @@ -20,7 +20,7 @@ "eslint": "^8.51.0", "eslint-config-prettier": "^9.0.0", "eslint-plugin-prettier": "^5.0.0", - "gopeed": "^1.0.5", + "gopeed": "^1.0.6", "prettier": "^3.0.3", "webpack": "^5.75.0", "webpack-cli": "^5.0.1" diff --git a/packages/gopeed-openapi/build/index.html b/packages/gopeed-openapi/build/index.html deleted file mode 100644 index 140b517..0000000 --- a/packages/gopeed-openapi/build/index.html +++ /dev/null @@ -1,16 +0,0 @@ - - - - - - - - - - - - - - \ No newline at end of file diff --git a/packages/gopeed-openapi/build/swagger.json b/packages/gopeed-openapi/build/swagger.json deleted file mode 100644 index b67365a..0000000 --- a/packages/gopeed-openapi/build/swagger.json +++ /dev/null @@ -1,593 +0,0 @@ -{ - "components": { - "examples": {}, - "headers": {}, - "parameters": {}, - "requestBodies": {}, - "responses": {}, - "schemas": { - "HttpMethod": { - "type": "string", - "enum": [ - "GET", - "POST", - "PUT", - "DELETE", - "PATCH", - "HEAD", - "OPTIONS", - "CONNECT", - "TRACE" - ] - }, - "HttpHeaders": { - "properties": {}, - "additionalProperties": { - "type": "string" - }, - "type": "object" - }, - "HttpReqExtra": { - "properties": { - "method": { - "$ref": "#/components/schemas/HttpMethod" - }, - "headers": { - "$ref": "#/components/schemas/HttpHeaders" - }, - "body": { - "type": "string" - } - }, - "type": "object", - "additionalProperties": false - }, - "BtReqExtra": { - "properties": { - "trackers": { - "items": { - "type": "string" - }, - "type": "array", - "description": "Tracker url list" - } - }, - "type": "object", - "additionalProperties": false - }, - "Request": { - "description": "Download request", - "properties": { - "url": { - "type": "string", - "description": "Request url, support http(s) and magnet and local torrent file" - }, - "extra": { - "anyOf": [ - { - "$ref": "#/components/schemas/HttpReqExtra" - }, - { - "$ref": "#/components/schemas/BtReqExtra" - } - ] - } - }, - "required": [ - "url" - ], - "type": "object", - "additionalProperties": false, - "example": { - "url": "https://example.com/file.mp4" - } - }, - "FileInfo": { - "properties": { - "name": { - "type": "string" - }, - "path": { - "type": "string" - }, - "size": { - "type": "number", - "format": "double" - }, - "req": { - "$ref": "#/components/schemas/Request", - "description": "Specify the request for this file" - } - }, - "required": [ - "name", - "path", - "size" - ], - "type": "object", - "additionalProperties": false - }, - "Resource": { - "description": "Resource info resloved from request, can contain multiple files", - "properties": { - "name": { - "type": "string" - }, - "size": { - "type": "number", - "format": "double" - }, - "range": { - "type": "boolean" - }, - "files": { - "items": { - "$ref": "#/components/schemas/FileInfo" - }, - "type": "array" - }, - "hash": { - "type": "string" - } - }, - "required": [ - "name", - "size", - "range", - "files" - ], - "type": "object", - "additionalProperties": false - }, - "ResolveResult": { - "properties": { - "id": { - "type": "string" - }, - "res": { - "$ref": "#/components/schemas/Resource" - } - }, - "required": [ - "id", - "res" - ], - "type": "object", - "additionalProperties": false - }, - "HttpOptExtra": { - "properties": { - "connections": { - "type": "number", - "format": "double", - "description": "Concurrent connections" - } - }, - "type": "object", - "additionalProperties": false - }, - "Options": { - "description": "Download options", - "properties": { - "name": { - "type": "string", - "description": "Specify the file name, if not set, use the name from resource" - }, - "path": { - "type": "string", - "description": "Specify the path to save the file, if not set, use the current directory" - }, - "selectFiles": { - "items": { - "type": "number", - "format": "double" - }, - "type": "array", - "description": "Select the index of the specified file, if not set, download all files" - }, - "extra": { - "$ref": "#/components/schemas/HttpOptExtra" - } - }, - "type": "object", - "additionalProperties": false - }, - "CreateTaskWithResolveResult": { - "properties": { - "rid": { - "type": "string", - "description": "Resolved result id" - }, - "opts": { - "$ref": "#/components/schemas/Options", - "description": "Download options" - } - }, - "required": [ - "rid" - ], - "type": "object", - "additionalProperties": false - }, - "CreateTaskWithRequest": { - "properties": { - "req": { - "$ref": "#/components/schemas/Request", - "description": "Download request" - }, - "opts": { - "$ref": "#/components/schemas/Options", - "description": "Download options" - } - }, - "required": [ - "req" - ], - "type": "object", - "additionalProperties": false - }, - "TaskStatus": { - "type": "string", - "enum": [ - "ready", - "running", - "pause", - "wait", - "error", - "done" - ] - }, - "TaskProgress": { - "properties": { - "used": { - "type": "number", - "format": "double", - "description": "Download used time(ns)" - }, - "speed": { - "type": "number", - "format": "double", - "description": "Download speed(byte/s)" - }, - "downloaded": { - "type": "number", - "format": "double", - "description": "Downloaded size(byte)" - } - }, - "required": [ - "used", - "speed", - "downloaded" - ], - "type": "object", - "additionalProperties": false - }, - "Task": { - "properties": { - "id": { - "type": "string" - }, - "meta": { - "properties": { - "opt": { - "$ref": "#/components/schemas/Options" - }, - "res": { - "$ref": "#/components/schemas/Resource" - }, - "req": { - "$ref": "#/components/schemas/Request" - } - }, - "required": [ - "opt", - "res", - "req" - ], - "type": "object" - }, - "status": { - "$ref": "#/components/schemas/TaskStatus" - }, - "progress": { - "$ref": "#/components/schemas/TaskProgress" - }, - "size": { - "type": "number", - "format": "double", - "description": "Task total size(byte)" - }, - "createdAt": { - "type": "string", - "description": "ISO 8601 format" - } - }, - "required": [ - "id", - "meta", - "status", - "progress", - "size", - "createdAt" - ], - "type": "object", - "additionalProperties": false - } - }, - "securitySchemes": { - "X-Api-Token": { - "type": "apiKey", - "name": "X-Api-Token", - "in": "header", - "description": "Api Token for authentication" - } - } - }, - "info": { - "title": "Introduction", - "version": "v1", - "description": "This API is gopeed RESTful API document. You can use this API to manage download tasks.\n\n# Response Format\n\nAll APIs return JSON format response. The response format is:\n\n```json\n{\n \"code\": 0,\n \"message\": \"\",\n \"data\": null\n}\n```\n\n- `code`: The response code, `0` means success, other values means error.\n- `message`: The response message, if `code` != `0`, this field will contain error message.\n- `data`: The response data, if `code` == `0`, this field will contain response data.\n\n# Authentication\n\nWhen configed API token in Gopeed, should pass `X-Api-Token` in request header.\n\n# JavaScript Library\n\nWe provide a JavaScript library to help you use this API. You can install it by npm:\n\n```bash\nnpm install @gopeed/rest\n```\n\nThen you can use it in your code:\n\n```js\nimport Client from \"@gopeed/rest\";\n\n(async function(){\n const client = new Client();\n // Config host and API token\n // const client = new Client({\"host:\":\"http://api.xxx.com\", \"token\": \"your api token\"});\n\n // Create a http download task\n await client.createTask({\n \"req\":{\n \"url\": \"https://gopeed.com\"\n }\n });\n\n // Create a bt download task\n await client.createTask({\n \"req\":{\n \"url\": \"magnet:?xt=urn:btih:xxx\"\n }\n });\n});\n````\n", - "license": { - "name": "MIT" - }, - "contact": { - "url": "https://gopeed.com" - } - }, - "openapi": "3.0.0", - "paths": { - "/api/v1/resolve": { - "post": { - "operationId": "Resolve", - "responses": { - "200": { - "description": "Ok", - "content": { - "application/json": { - "schema": { - "$ref": "#/components/schemas/ResolveResult" - } - } - } - } - }, - "description": "Resolve resource info from request, can contain multiple files", - "summary": "Resolve a request", - "security": [ - { - "X-Api-Token": [] - } - ], - "parameters": [], - "requestBody": { - "required": true, - "content": { - "application/json": { - "schema": { - "$ref": "#/components/schemas/Request" - } - } - } - } - } - }, - "/api/v1/tasks": { - "post": { - "operationId": "CreateTask", - "responses": { - "200": { - "description": "Ok", - "content": { - "application/json": { - "schema": { - "type": "string" - } - } - } - } - }, - "description": "Create a download task, there has two ways to create a task:\n1. Create a task with resolved result, you can get resolved result from `/api/v1/resolve`\n2. Create a task directly with request", - "summary": "Create a task", - "security": [ - { - "X-Api-Token": [] - } - ], - "parameters": [], - "requestBody": { - "required": true, - "content": { - "application/json": { - "schema": { - "anyOf": [ - { - "$ref": "#/components/schemas/CreateTaskWithResolveResult" - }, - { - "$ref": "#/components/schemas/CreateTaskWithRequest" - } - ] - } - } - } - } - }, - "get": { - "operationId": "GetTasks", - "responses": { - "200": { - "description": "Ok", - "content": { - "application/json": { - "schema": { - "items": { - "$ref": "#/components/schemas/Task" - }, - "type": "array" - } - } - } - } - }, - "description": "Get task list", - "summary": "Get task list", - "security": [ - { - "X-Api-Token": [] - } - ], - "parameters": [ - { - "description": "- Filter by task status, can be multiple", - "in": "query", - "name": "status", - "required": false, - "schema": { - "default": [], - "type": "array", - "items": { - "$ref": "#/components/schemas/TaskStatus" - } - } - } - ] - } - }, - "/api/v1/tasks/{id}/pause": { - "put": { - "operationId": "PauseTask", - "responses": { - "200": { - "description": "" - } - }, - "description": "Pause a task", - "summary": "Pause a task", - "security": [ - { - "X-Api-Token": [] - } - ], - "parameters": [ - { - "description": "- Task id", - "in": "path", - "name": "id", - "required": true, - "schema": { - "type": "string" - } - } - ] - } - }, - "/api/v1/tasks/{id}/continue": { - "put": { - "operationId": "ContinueTask", - "responses": { - "200": { - "description": "" - } - }, - "description": "Continue a task", - "summary": "Continue a task", - "security": [ - { - "X-Api-Token": [] - } - ], - "parameters": [ - { - "description": "- Task id", - "in": "path", - "name": "id", - "required": true, - "schema": { - "type": "string" - } - } - ] - } - }, - "/api/v1/tasks/pause": { - "put": { - "operationId": "PauseAllTasks", - "responses": { - "200": { - "description": "" - } - }, - "description": "Pause all tasks", - "summary": "Pause all tasks", - "security": [ - { - "X-Api-Token": [] - } - ], - "parameters": [] - } - }, - "/api/v1/tasks/continue": { - "put": { - "operationId": "ContinueAllTasks", - "responses": { - "200": { - "description": "" - } - }, - "description": "Continue all tasks", - "summary": "Continue all tasks", - "security": [ - { - "X-Api-Token": [] - } - ], - "parameters": [] - } - }, - "/api/v1/tasks/{id}": { - "delete": { - "operationId": "DeleteTask", - "responses": { - "204": { - "description": "No content" - } - }, - "description": "Delete a task", - "summary": "Delete a task", - "security": [ - { - "X-Api-Token": [] - } - ], - "parameters": [ - { - "description": "- Task id", - "in": "path", - "name": "id", - "required": true, - "schema": { - "type": "string" - } - }, - { - "description": "- Delete files", - "in": "query", - "name": "force", - "required": false, - "schema": { - "default": false, - "type": "boolean" - } - } - ] - } - } - }, - "servers": [ - { - "url": "http://127.0.0.1:9999/" - } - ] -} \ No newline at end of file diff --git a/packages/gopeed-rest/package.json b/packages/gopeed-rest/package.json index 1ad8215..e4ac532 100644 --- a/packages/gopeed-rest/package.json +++ b/packages/gopeed-rest/package.json @@ -1,6 +1,6 @@ { "name": "@gopeed/rest", - "version": "1.0.5", + "version": "1.0.6", "description": "", "main": "dist/index.js", "exports": { diff --git a/packages/gopeed-types/package.json b/packages/gopeed-types/package.json index 74b1337..0b63101 100644 --- a/packages/gopeed-types/package.json +++ b/packages/gopeed-types/package.json @@ -1,6 +1,6 @@ { "name": "@gopeed/types", - "version": "1.0.5", + "version": "1.0.6", "description": "", "main": "dist/index.js", "exports": { diff --git a/packages/gopeed-types/src/index.ts b/packages/gopeed-types/src/index.ts index 8ae7c30..bedf2b9 100644 --- a/packages/gopeed-types/src/index.ts +++ b/packages/gopeed-types/src/index.ts @@ -1,12 +1,36 @@ export type HttpMethod = 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH' | 'HEAD' | 'OPTIONS' | 'CONNECT' | 'TRACE'; export type HttpHeaders = { [key: string]: string }; +/** + * HTTP request extra options + * @example { + * "method": "GET", + * "headers": { + * "Cookie": "xxx" + * } + * } + */ export interface HttpReqExtra { + /** + * HTTP request method + */ method?: HttpMethod; + /** + * HTTP request headers + */ headers?: HttpHeaders; + /** + * HTTP request body + */ body?: string | undefined; } +/** + * Bt request extra options + * @example { + * "trackers": ["udp://tracker.opentrackr.org:1337/announce"] + * } + */ export interface BtReqExtra { /** * Tracker url list @@ -14,6 +38,12 @@ export interface BtReqExtra { trackers?: string[]; } +/** + * HTTP download extra options + * @example { + * "connections": 32 + * } + */ export interface HttpOptExtra { /** * Concurrent connections @@ -32,12 +62,32 @@ export interface Request { * Request url, support http(s) and magnet and local torrent file */ url: string; + /** + * Extra request options + */ extra?: HttpReqExtra | BtReqExtra; } +/** + * File info + * @example { + * "name": "file.mp4", + * "path": "", + * "size": 1024 + * } + */ export interface FileInfo { + /** + * File name + */ name: string; + /** + * File path, relative to the resource, e.g. "path/to" + */ path: string; + /** + * File size(byte) + */ size: number; /** @@ -50,9 +100,21 @@ export interface FileInfo { * Resource info resloved from request, can contain multiple files */ export interface Resource { + /** + * When name is not blank, it means that the resource is a folder resource, and the name is the folder name + */ name: string; + /** + * Resource total size(byte) + */ size: number; + /** + * Whether the resource supports breakpoint continuation + */ range: boolean; + /** + * Resource files list, only when the resource is a folder resource will contain multiple files, otherwise it will only contain one file + */ files: FileInfo[]; hash?: string; } @@ -78,6 +140,9 @@ export interface Options { * Select the index of the specified file, if not set, download all files */ selectFiles?: number[]; + /** + * Download extra options + */ extra?: HttpOptExtra; } @@ -99,6 +164,9 @@ export interface TaskProgress { } export interface Task { + /** + * Task id + */ id: string; /** * Task metadata @@ -114,6 +182,9 @@ export interface Task { * @example "running" */ status: TaskStatus; + /** + * Task progress + */ progress: TaskProgress; /** * Task total size(byte) diff --git a/packages/gopeed/package.json b/packages/gopeed/package.json index 4a5a29d..7647f2d 100644 --- a/packages/gopeed/package.json +++ b/packages/gopeed/package.json @@ -1,6 +1,6 @@ { "name": "gopeed", - "version": "1.0.5", + "version": "1.0.6", "description": "", "main": "dist/index.js", "exports": {