### Install and Run Backend Development Server Source: https://github.com/sub-store-org/sub-store/blob/master/_autodocs/README.md Navigate to the backend directory, install dependencies, and start the development server using pnpm. The server will be accessible at http://localhost:3000. ```bash cd backend pnpm install SUB_STORE_BACKEND_API_PORT=3000 pnpm dev:esbuild ``` -------------------------------- ### Example Response for Get Settings Source: https://github.com/sub-store-org/sub-store/blob/master/_autodocs/endpoints.md Illustrates the structure of the response when retrieving all application settings. Note the various configuration options available. ```javascript { username: string, gistToken: string, syncPlatform: string, // 'github' | 'gitlab' defaultTimeout: number, githubProxy: string, githubApiUrl: string, githubApiTimeout: number, defaultProxy: string, allowUnsupportedProxy: boolean, backendRequestConcurrency: number, backendRequestConcurrencyWaitTime: number, artifactSyncBatchSize: number, cacheThreshold: number, resourceCacheTtl: number, headersCacheTtl: number, scriptCacheTtl: number, logsMaxCount: number, gistUpload: string, // 'basic' | 'age' notificationUrl: string, appearanceSetting: { invalidShareFakeNode: boolean, editorLanguage: string, theme: string } } ``` -------------------------------- ### HTTP Server Setup Source: https://github.com/sub-store-org/sub-store/blob/master/_autodocs/api-reference/core-api.md Initializes and starts the Express server for the Sub-Store backend API. Configure the port and host using parameters or environment variables. ```javascript import express from '@/vendor/express'; const $app = express({ substore: $, port: 3000, // SUB_STORE_BACKEND_API_PORT env var host: '::' // SUB_STORE_BACKEND_API_HOST env var }); $app.start(); ``` -------------------------------- ### Start Development Server Source: https://github.com/sub-store-org/sub-store/blob/master/_autodocs/configuration.md Command to start the Sub-Store server using npm and esbuild for development. ```bash npm run dev:esbuild ``` -------------------------------- ### HTTP Server Setup Source: https://github.com/sub-store-org/sub-store/blob/master/_autodocs/api-reference/core-api.md Configures and starts the Express HTTP server for the Sub-Store backend. It allows customization of the port, host, and integrates with the global application context. ```APIDOC ## HTTP Server Setup ### Description Configures and starts the Express HTTP server for the Sub-Store backend. It allows customization of the port, host, and integrates with the global application context. ### Method POST ### Endpoint / ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **substore** (OpenAPI) - Required - Global app context with persistence and logging - **port** (number) - Optional - Server port (default: 3000) - **host** (string) - Optional - Server host (default: '::' for IPv6) ### Request Example ```json { "substore": "global_app_context", "port": 3000, "host": "::" } ``` ### Response #### Success Response (200) Indicates the server has started successfully. #### Response Example ```json { "message": "Server started successfully" } ``` ### Environment Variables - **SUB_STORE_BACKEND_API_PORT** (number) - Default: 3000 - HTTP server port - **SUB_STORE_BACKEND_API_HOST** (string) - Default: '::' - HTTP server host - **SUB_STORE_BACKEND_MERGE** (boolean) - Default: false - Merge backend and frontend into single server - **SUB_STORE_BACKEND_PREFIX** (string) - Default: — - API prefix path - **SUB_STORE_FRONTEND_BACKEND_PATH** (string) - Default: — - Frontend-to-backend route prefix - **SUB_STORE_FRONTEND_PATH** (string) - Default: — - Frontend static files directory - **SUB_STORE_DATA_BASE_PATH** (string) - Default: '.' - Data storage base path - **SUB_STORE_CORS_ALLOWED_ORIGINS** (string) - Default: '*' - CORS allowlist (comma-separated) ``` -------------------------------- ### Example GitHub Proxy Configuration Source: https://github.com/sub-store-org/sub-store/blob/master/_autodocs/api-reference/download-utilities.md An example of how to set the GitHub proxy configuration within $.read(SETTINGS_KEY). This example shows how a raw GitHub URL is transformed when routed through the proxy. ```javascript // Settings in $.read(SETTINGS_KEY) { githubProxy: 'https://ghproxy.com', githubProxyRegex: 'github\.com|githubusercontent\.com' } // URL: https://raw.githubusercontent.com/user/repo/file // Becomes: https://ghproxy.com/https://raw.githubusercontent.com/user/repo/file ``` -------------------------------- ### Get Node Info Response Example Source: https://github.com/sub-store-org/sub-store/blob/master/_autodocs/endpoints.md Example of the JSON response structure when requesting node information. This includes details about the operating environment and software version. ```javascript { env: string, // 'node', 'qx', 'loon', 'surge', etc. version: string, platform: string } ``` -------------------------------- ### Example .env File for Sub-Store Configuration Source: https://github.com/sub-store-org/sub-store/blob/master/_autodocs/configuration.md An example of a .env file demonstrating common Sub-Store environment variable settings for server, merge mode, frontend path, and CORS. ```bash # Server SUB_STORE_BACKEND_API_PORT=3000 SUB_STORE_BACKEND_API_HOST=0.0.0.0 SUB_STORE_DATA_BASE_PATH=./data # Merge mode (single executable serves frontend + backend) SUB_STORE_BACKEND_MERGE=true SUB_STORE_FRONTEND_PATH=./dist # CORS SUB_STORE_CORS_ALLOWED_ORIGINS=https://example.com ``` -------------------------------- ### Local Subscription Example Source: https://github.com/sub-store-org/sub-store/blob/master/_autodocs/types.md An example configuration for a local subscription. This demonstrates the use of the 'local' source type and the 'content' field for providing subscription data directly. ```javascript { name: 'my-local-sub', source: 'local', content: `ss://cipher:password@host:port#proxy-name`, enabled: true } ``` -------------------------------- ### Collection Example Source: https://github.com/sub-store-org/sub-store/blob/master/_autodocs/types.md An example of a collection configuration named 'office-proxies', demonstrating the use of subscriptions, exclusions, and operators. ```javascript { name: 'office-proxies', subscriptions: ['sub-us', 'sub-sg', 'sub-hk'], excludeSubscriptions: ['sub-test'], operators: [ { type: 'region-filter', region: ['us', 'sg'] }, { type: 'regex-filter', pattern: '(?!.*test)' }, { type: 'sort' } ], enabled: true } ``` -------------------------------- ### Subscription Artifact Example Source: https://github.com/sub-store-org/sub-store/blob/master/_autodocs/types.md An example of a Subscription Artifact configured for HTTP delivery. ```javascript { name: 'my-artifact', type: 'subscription', source: 'my-sub', platform: 'Clash', sync: 'manual', url: 'https://sub.example.com/my-artifact.yaml' } ``` -------------------------------- ### Mihomo Config (Collection-based) Example Source: https://github.com/sub-store-org/sub-store/blob/master/_autodocs/types.md An example of a File object for a Mihomo configuration sourced from a collection. ```javascript { name: 'mihomo-config', sourceType: 'collection', sourceName: 'office-proxies', type: 'yaml' } ``` -------------------------------- ### Preview Endpoint Examples Source: https://github.com/sub-store-org/sub-store/blob/master/_autodocs/api-reference/preview-utilities.md These are example endpoints for generating previews of subscriptions and collections. They accept query parameters to customize the preview output. ```HTTP GET /api/preview/:name GET /api/preview/collection/:name ``` -------------------------------- ### Install Node Dependencies Source: https://github.com/sub-store-org/sub-store/blob/master/README.md Installs project dependencies using pnpm. Navigate to the 'backend' directory before running. ```bash pnpm i ``` -------------------------------- ### Example Response for Get Logs Source: https://github.com/sub-store-org/sub-store/blob/master/_autodocs/endpoints.md Shows the format of the log entries returned by the API. Each entry includes a timestamp, log level, and message. ```javascript [ { timestamp: number, level: string, // 'debug', 'info', 'warn', 'error' message: string }, // ... ] ``` -------------------------------- ### Local Text File Example Source: https://github.com/sub-store-org/sub-store/blob/master/_autodocs/types.md An example of a File object representing a local text file. ```javascript { name: 'rules.txt', type: 'text', content: 'DOMAIN,example.com,DIRECT\nDOMAIN,google.com,PROXY', source: 'local' } ``` -------------------------------- ### Error Logging Examples Source: https://github.com/sub-store-org/sub-store/blob/master/_autodocs/errors.md Examples of how to log errors and warnings using the $.error and $.warn functions, including contextual information like subscription names and URLs. ```javascript $.error(`Subscription ${name} not found`); $.error(`Failed to download from ${maskAgeSecretInUrl(url)}: ${err}`); $.warn(`UUID may be invalid: ${proxy.name} ${proxy.uuid}`); ``` -------------------------------- ### Remote Subscription Example Source: https://github.com/sub-store-org/sub-store/blob/master/_autodocs/types.md An example configuration for a remote subscription. This includes essential fields like name, URL, source type, merge strategy, proxy settings, and update interval. ```javascript { name: 'my-remote-sub', url: 'https://api.example.com/sub', source: 'remote', mergeSources: 'merge', proxy: 'http://proxy:8080', enabled: true, updateInterval: 360 // 6 hours } ``` -------------------------------- ### GitHub Sync Artifact Example Source: https://github.com/sub-store-org/sub-store/blob/master/_autodocs/types.md An example of an Artifact object configured for automatic synchronization with GitHub. ```javascript { name: 'synced-artifact', type: 'collection', source: 'office-proxies', syncPlatform: 'github', sync: 'auto', cron: '0 * * * *', syncNotification: true, agePublicKey: 'age1...' } ``` -------------------------------- ### Example Flow Info Object Source: https://github.com/sub-store-org/sub-store/blob/master/_autodocs/types.md An example of a populated Flow Info object, illustrating typical values for downloaded/uploaded bytes, total quota, expiration date, and usage percentage. ```javascript { download: 1073741824, upload: 2147483648, total: 10737418240, expire: 1735689600, remainingDays: 184, usedPercent: 30 } ``` -------------------------------- ### Example Webhook Service POST Request Source: https://github.com/sub-store-org/sub-store/blob/master/_autodocs/configuration.md An example of how a webhook service would receive a POST request with the notification payload. This demonstrates the expected format for incoming requests. ```bash POST https://webhooks.example.com/sub-store Content-Type: application/json { "title": "🌍 Sub-Store", "subtitle": "my-artifact", "body": "Sync completed successfully" } ``` -------------------------------- ### Egern Module Installation Source: https://github.com/sub-store-org/sub-store/blob/master/config/README.md Install this YAML configuration file for Egern to use Sub-Store. ```yaml https://raw.githubusercontent.com/sub-store-org/Sub-Store/master/config/Egern.yaml ``` -------------------------------- ### Remote YAML File Example Source: https://github.com/sub-store-org/sub-store/blob/master/_autodocs/types.md An example of a File object representing a remote YAML file, including proxy settings. ```javascript { name: 'clash-config', type: 'yaml', url: 'https://raw.githubusercontent.com/user/repo/config.yaml', source: 'remote', proxy: 'http://proxy:8080' } ``` -------------------------------- ### QX Subscription Rewrite Snippet Source: https://github.com/sub-store-org/sub-store/blob/master/config/README.md Install this snippet for QX to manage subscription rewrites. ```bash https://raw.githubusercontent.com/sub-store-org/Sub-Store/master/config/QX.snippet ``` -------------------------------- ### Run Development Server Source: https://github.com/sub-store-org/sub-store/blob/master/README.md Starts the development server with a specified API port. This command uses esbuild for development builds. ```bash SUB_STORE_BACKEND_API_PORT=3000 pnpm esbuild:dev ``` -------------------------------- ### Artifact Management Example Source: https://github.com/sub-store-org/sub-store/blob/master/_autodocs/api-reference/database-utilities.md Shows how to manage artifacts, including checking for existence, adding new artifacts with position preference, and writing changes back to storage. ```javascript const artifacts = $.read(ARTIFACTS_KEY); // Check if artifact exists if (findByName(artifacts, 'my-artifact')) { $.info('Artifact found'); } // Add artifact with position preference const newArtifact = { name: 'new-artifact', type: 'subscription', source: 'my-sub' }; insertByPosition(artifacts, newArtifact, 'bottom'); $.write(artifacts, ARTIFACTS_KEY); ``` -------------------------------- ### Subscription Management Example Source: https://github.com/sub-store-org/sub-store/blob/master/_autodocs/api-reference/database-utilities.md Demonstrates common subscription management tasks using database utility functions. Includes reading, finding, updating, inserting, and deleting subscriptions. ```javascript import { findByName, findIndexByName, updateByName, deleteByName, insertByPosition } from '@/utils/database'; import {SUBS_KEY} from '@/constants'; import $ from '@/core/app'; // Read all subscriptions const allSubs = $.read(SUBS_KEY); // Find a subscription const sub = findByName(allSubs, 'my-subscription'); // Update subscription if (sub) { updateByName(allSubs, 'my-subscription', { ...sub, url: 'https://newurl.com', enabled: true }); $.write(allSubs, SUBS_KEY); } // Create new subscription const newSub = { name: 'new-sub', url: 'https://example.com', enabled: true }; insertByPosition(allSubs, newSub, 'bottom'); $.write(allSubs, SUBS_KEY); // Delete subscription deleteByName(allSubs, 'old-sub'); $.write(allSubs, SUBS_KEY); ``` -------------------------------- ### Example Script Transformer Usage Source: https://github.com/sub-store-org/sub-store/blob/master/_autodocs/api-reference/preview-utilities.md An example of a script transformer configuration that adds a custom header to the content if it contains 'proxies:'. ```javascript { type: 'script-transformer', script: ` // Add custom header to output if (content.includes('proxies:')) { return '# Generated by Sub-Store\n' + content; } return content; ` } ``` -------------------------------- ### Surge Rule Format Example Source: https://github.com/sub-store-org/sub-store/blob/master/_autodocs/api-reference/rule-utilities.md Provides an example of the Surge rule format, including rules for exact domains, domain suffixes, IP CIDR blocks, and a final catch-all rule. ```plaintext # Exact domain DOMAIN,example.com,DIRECT # Domain suffix DOMAIN-SUFFIX,google.com,PROXY # IP CIDR IP-CIDR,192.168.0.0/16,DIRECT,no-resolve # Default FINAL,PROXY ``` -------------------------------- ### Clash Rule Format Example Source: https://github.com/sub-store-org/sub-store/blob/master/_autodocs/api-reference/rule-utilities.md Shows an example of the Clash rule format, which uses a YAML structure and keywords like 'DOMAIN', 'DOMAIN-SUFFIX', 'IP-CIDR', and 'MATCH' for rule definition. ```yaml rules: - DOMAIN,example.com,DIRECT - DOMAIN-SUFFIX,google.com,PROXY - IP-CIDR,192.168.0.0/16,DIRECT - MATCH,PROXY ``` -------------------------------- ### Base64 Transformer Example Output Source: https://github.com/sub-store-org/sub-store/blob/master/_autodocs/api-reference/preview-utilities.md Illustrates the expected output format after applying the Base64 transformer. ```javascript // Output: "c3M6Ly9jaXBoZXI6cGFzc3dvcmRAaG9zdDpwb3J0I3Byb3h5..." ``` -------------------------------- ### Loon Plugin Installation Source: https://github.com/sub-store-org/sub-store/blob/master/config/README.md Install the Sub-Store plugin for Loon to enable its features. For newer versions, a specific parser plugin is recommended. ```bash https://raw.githubusercontent.com/sub-store-org/Sub-Store/master/config/Loon.plugin ``` -------------------------------- ### Example Proxy URI Scheme Source: https://github.com/sub-store-org/sub-store/blob/master/README.md Demonstrates the format for a proxy URI scheme, including authentication and transport protocols. ```text socks5+tls://user:pass@ip:port#name ``` -------------------------------- ### Get All Files Source: https://github.com/sub-store-org/sub-store/blob/master/_autodocs/endpoints.md Lists all files in the system, returning basic metadata for each. ```APIDOC ## GET /api/files ### Description Lists all files. ### Method GET ### Endpoint /api/files ### Response #### Success Response (200) [ { name: string, type: string, content: string, url: string, source: string, sourceType: string, sourceName: string }, // ... ] ``` -------------------------------- ### Generate Share Token Response Example Source: https://github.com/sub-store-org/sub-store/blob/master/_autodocs/endpoints.md Example of the JSON response when generating a share token. It includes the token itself, its expiration timestamp, and the associated path. ```javascript { token: string, expire: number, path: string } ``` -------------------------------- ### REST API: Get Settings Source: https://github.com/sub-store-org/sub-store/blob/master/_autodocs/README.md Retrieves the current application settings by making a GET request to the settings endpoint. ```bash # Get settings curl http://localhost:3000/api/settings ``` -------------------------------- ### Verify Share Token Response Example Source: https://github.com/sub-store-org/sub-store/blob/master/_autodocs/endpoints.md Example of the JSON response when verifying a share token. The response indicates whether the token is valid and provides its associated path and expiration time. ```javascript { valid: boolean, path: string, expire: number } ``` -------------------------------- ### Collection Management Example Source: https://github.com/sub-store-org/sub-store/blob/master/_autodocs/api-reference/database-utilities.md Illustrates how to manage collections, including reading, finding, updating subscriptions within a collection, and renaming a collection while updating associated artifacts. ```javascript // Get all collections const collections = $.read(COLLECTIONS_KEY); // Find specific collection const collection = findByName(collections, 'my-collection'); // Update collection subscriptions if (collection) { collection.subscriptions = ['sub-1', 'sub-2', 'sub-3']; updateByName(collections, 'my-collection', collection); $.write(collections, COLLECTIONS_KEY); } // Rename collection (important: update in artifacts too) const index = findIndexByName(collections, 'old-name'); if (index !== -1) { const col = collections[index]; col.name = 'new-name'; updateByName(collections, 'old-name', col); // Update artifacts referring this collection const artifacts = $.read(ARTIFACTS_KEY); for (const artifact of artifacts) { if (artifact.source === 'old-name') { artifact.source = 'new-name'; } } $.write(artifacts, ARTIFACTS_KEY); $.write(collections, COLLECTIONS_KEY); } ``` -------------------------------- ### Loon Rule Format Example Source: https://github.com/sub-store-org/sub-store/blob/master/_autodocs/api-reference/rule-utilities.md Presents an example of the Loon rule format, which is similar to Surge but uses different keywords for domain matching and lacks the 'no-resolve' option. ```plaintext # Exact domain domain,example.com,DIRECT # Domain suffix domain_suffix,google.com,PROXY # IP CIDR ip_cidr,192.168.0.0/16,DIRECT # Default final,PROXY ``` -------------------------------- ### Surge Module without Ability Parameter Source: https://github.com/sub-store-org/sub-store/blob/master/config/README.md Install this classic version of the Surge module if the 'ability' parameter is not required. ```bash https://raw.githubusercontent.com/sub-store-org/Sub-Store/master/config/Surge-Noability.sgmodule ``` -------------------------------- ### Production Docker Deployment Source: https://github.com/sub-store-org/sub-store/blob/master/_autodocs/configuration.md Example Docker run command for deploying Sub-Store in a production environment. It sets environment variables, mounts a volume for data, and maps ports. ```bash docker run -d \ -e SUB_STORE_BACKEND_API_PORT=3000 \ -e SUB_STORE_BACKEND_API_HOST=0.0.0.0 \ -e SUB_STORE_DATA_BASE_PATH=/data \ -e SUB_STORE_CORS_ALLOWED_ORIGINS=https://my.domain.com \ -e SUB_STORE_BACKEND_MERGE=true \ -e SUB_STORE_FRONTEND_PATH=/app/frontend \ -v sub-store-data:/data \ -p 3000:3000 \ sub-store:latest ``` -------------------------------- ### List All Subscriptions Response Source: https://github.com/sub-store-org/sub-store/blob/master/_autodocs/endpoints.md Example structure for the response when listing all subscriptions, which is an array of subscription objects. ```JSON [ { name: string, url: string, ... }, // ... ] ``` -------------------------------- ### Get All Application Settings Source: https://github.com/sub-store-org/sub-store/blob/master/_autodocs/endpoints.md Retrieves all current application settings. This endpoint returns a comprehensive object detailing various configuration parameters. ```http GET /api/settings ``` -------------------------------- ### Get Settings Source: https://github.com/sub-store-org/sub-store/blob/master/_autodocs/endpoints.md Retrieves all application settings. This endpoint allows fetching the current configuration of the application. ```APIDOC ## GET /api/settings ### Description Retrieves all application settings. ### Method GET ### Endpoint /api/settings ### Response #### Success Response (200) - **username** (string) - **gistToken** (string) - **syncPlatform** (string) - 'github' | 'gitlab' - **defaultTimeout** (number) - **githubProxy** (string) - **githubApiUrl** (string) - **githubApiTimeout** (number) - **defaultProxy** (string) - **allowUnsupportedProxy** (boolean) - **backendRequestConcurrency** (number) - **backendRequestConcurrencyWaitTime** (number) - **artifactSyncBatchSize** (number) - **cacheThreshold** (number) - **resourceCacheTtl** (number) - **headersCacheTtl** (number) - **scriptCacheTtl** (number) - **logsMaxCount** (number) - **gistUpload** (string) - 'basic' | 'age' - **notificationUrl** (string) - **appearanceSetting** (object) - **invalidShareFakeNode** (boolean) - **editorLanguage** (string) - **theme** (string) ### Response Example { "username": "user1", "gistToken": "token123", "syncPlatform": "github", "defaultTimeout": 30, "githubProxy": "", "githubApiUrl": "https://api.github.com", "githubApiTimeout": 10, "defaultProxy": "", "allowUnsupportedProxy": false, "backendRequestConcurrency": 5, "backendRequestConcurrencyWaitTime": 1000, "artifactSyncBatchSize": 100, "cacheThreshold": 1024, "resourceCacheTtl": 3600, "headersCacheTtl": 600, "scriptCacheTtl": 120, "logsMaxCount": 1000, "gistUpload": "basic", "notificationUrl": "", "appearanceSetting": { "invalidShareFakeNode": false, "editorLanguage": "en", "theme": "dark" } } ``` -------------------------------- ### Get All Artifacts Source: https://github.com/sub-store-org/sub-store/blob/master/_autodocs/endpoints.md Lists all artifacts available in the system. The response includes detailed properties for each artifact. ```HTTP GET /api/artifacts ``` ```javascript [ { name: string, url: string, type: string, // 'subscription' | 'collection' | 'file' source: string, // Source name platform: string, // Target platform sync: string, // Sync mode: 'auto' | 'manual' syncInterval: number, syncPlatform: string, // 'github' | 'gitlab' syncNotification: boolean, agePublicKey: string, cron: string // Cron expression for auto-sync }, // ... ] ``` -------------------------------- ### Get Subscription Source: https://github.com/sub-store-org/sub-store/blob/master/_autodocs/endpoints.md Retrieves the configuration details for a specific subscription. ```APIDOC ## GET /api/sub/:name ### Description Retrieves a subscription configuration. ### Method GET ### Endpoint /api/sub/:name ### Parameters #### Path Parameters - **name** (string) - Required - Subscription name ### Response #### Success Response (200) - **name** (string) - Subscription name - **url** (string) - Subscription URL or multiple URLs (newline-separated) - **source** (string) - 'local' or 'remote' - **mergeSources** (string) - 'merge' | 'localFirst' | 'remoteFirst' - **subUserinfo** (string) - Custom flow info header or URL - **proxy** (string) - Proxy to use for downloads - **ua** (string) - Custom User-Agent - **includeUnsupportedProxy** (boolean) - **enabled** (boolean) - **updateInterval** (number) - Minutes between auto-sync ### Response Example ```json { "name": "my-sub", "url": "http://example.com/sub.txt", "source": "remote", "mergeSources": "remoteFirst", "subUserinfo": "userinfo", "proxy": "http://proxy.com:8080", "ua": "MyClient/1.0", "includeUnsupportedProxy": false, "enabled": true, "updateInterval": 60 } ``` ### Errors - `ResourceNotFoundError` (404): Subscription not found ``` -------------------------------- ### Stash Override Configuration Source: https://github.com/sub-store-org/sub-store/blob/master/config/README.md Install this override file for Stash to configure its behavior. ```bash https://raw.githubusercontent.com/sub-store-org/Sub-Store/master/config/Stash.stoverride ``` -------------------------------- ### Get All Files (Whole) Source: https://github.com/sub-store-org/sub-store/blob/master/_autodocs/endpoints.md Retrieves all files along with their complete content. ```APIDOC ## GET /api/wholeFiles ### Description Gets all files with full content. ### Method GET ### Endpoint /api/wholeFiles ### Response #### Success Response (200) Array of file objects with complete content ``` -------------------------------- ### Surge Beta Module Source: https://github.com/sub-store-org/sub-store/blob/master/config/README.md Install the beta version of the Surge module for compatibility with the latest Surge iOS TestFlight features. ```bash https://raw.githubusercontent.com/sub-store-org/Sub-Store/master/config/Surge-Beta.sgmodule ``` -------------------------------- ### Run Development Server in Termux Source: https://github.com/sub-store-org/sub-store/blob/master/README.md Starts the development server in Termux, running multiple development tasks in parallel. Sets the API port to 3000. ```bash SUB_STORE_BACKEND_API_PORT=3000 pnpm run --parallel "/^dev:.*/" ``` -------------------------------- ### Surge Default Module Source: https://github.com/sub-store-org/sub-store/blob/master/config/README.md Install the official default Surge module, which supports editing parameters within the app. ```bash https://raw.githubusercontent.com/sub-store-org/Sub-Store/master/config/Surge.sgmodule ``` -------------------------------- ### Database Operations for Subscriptions Source: https://github.com/sub-store-org/sub-store/blob/master/_autodocs/README.md Provides examples for finding, updating, deleting, and inserting subscription data in the database, ensuring the changes are persisted. ```javascript import { findByName, findIndexByName, updateByName, deleteByName, insertByPosition } from '@/utils/database'; const subs = $.read(SUBS_KEY); const sub = findByName(subs, 'my-sub'); updateByName(subs, 'my-sub', newSub); deleteByName(subs, 'my-sub'); insertByPosition(subs, newSub, 'top'); $.write(subs, SUBS_KEY); ``` -------------------------------- ### Core API Modules Source: https://github.com/sub-store-org/sub-store/blob/master/_autodocs/README.md The Core API module handles server setup, configuration, routing, middleware, and request handling. ```APIDOC ## Core API This module is responsible for the fundamental aspects of the Sub-Store backend server. ### Key Responsibilities: - Server setup and configuration - Routing registration - Middleware and request handling - Environment detection Detailed information can be found in `api-reference/core-api.md`. ``` -------------------------------- ### Development Environment Variables Source: https://github.com/sub-store-org/sub-store/blob/master/_autodocs/configuration.md Configuration for the .env file in a development setup. This includes API port, host, data path, and CORS settings. ```bash # .env file for development SUB_STORE_BACKEND_API_PORT=3000 SUB_STORE_BACKEND_API_HOST=localhost SUB_STORE_DATA_BASE_PATH=./data SUB_STORE_CORS_ALLOWED_ORIGINS=* ``` -------------------------------- ### Build and Run Production Backend Source: https://github.com/sub-store-org/sub-store/blob/master/_autodocs/README.md Bundle the backend using pnpm esbuild and then run the compiled JavaScript file. This prepares the application for deployment. ```bash # Build pnpm bundle:esbuild # Run node sub-store.min.js ``` -------------------------------- ### Success Response Example Source: https://github.com/sub-store-org/sub-store/blob/master/_autodocs/api-reference/core-api.md Sends a JSON response with a specified status code upon successful operation. Use this to return data to the client. ```javascript success(res, { name: 'my-sub', url: 'https://example.com/sub' }, 201); ``` -------------------------------- ### Subscription Configuration Response Source: https://github.com/sub-store-org/sub-store/blob/master/_autodocs/endpoints.md Example JSON response structure for a subscription's configuration, including its name, URL, source, merge strategy, proxy, and update interval. ```JSON { name: string, // Subscription name url: string, // Subscription URL or multiple URLs (newline-separated) source: string, // 'local' or 'remote' mergeSources: string, subUserinfo: string, // Custom flow info header or URL proxy: string, // Proxy to use for downloads ua: string, // Custom User-Agent includeUnsupportedProxy: boolean, enabled: boolean, updateInterval: number } ``` -------------------------------- ### Initialize Application and Context Source: https://github.com/sub-store-org/sub-store/blob/master/_autodocs/README.md Sets up the global OpenAPI instance, creates a new application context, and demonstrates basic data persistence and logging operations. ```javascript // Entry point import $ from '@/core/app'; // Global OpenAPI instance // Create context import { OpenAPI } from '@/vendor/open-api'; const ctx = new OpenAPI('my-app'); // Persist data $.write(data, 'my-key'); const data = $.read('my-key'); // Log $.info('Message'); $.error('Error message'); $.notify('Title', 'Subtitle', 'Body'); ``` -------------------------------- ### InternalServerError Example Source: https://github.com/sub-store-org/sub-store/blob/master/_autodocs/errors.md Use this error for unexpected server-side issues or processing failures. Ensure the correct error code and a descriptive message are provided. ```javascript import { InternalServerError } from '@/restful/errors'; throw new InternalServerError( 'FAILED_TO_GET_SETTINGS', 'Failed to get settings', `Reason: ${e.message}` ); ``` -------------------------------- ### Share Token Middleware Example Source: https://github.com/sub-store-org/sub-store/blob/master/_autodocs/api-reference/core-api.md Consumes a share token from the query parameters for validating access to shared resources. This is used when the SUB_STORE_BACKEND_MERGE flag is enabled. ```javascript const token = consumeShareToken({ token: req.query.token, pathname: req._parsedUrl.pathname }); ``` -------------------------------- ### Import Download Utilities Source: https://github.com/sub-store-org/sub-store/blob/master/_autodocs/api-reference/download-utilities.md Import the main download function and the downloadFile utility from the download module. ```javascript import download, { downloadFile } from '@/utils/download'; ``` -------------------------------- ### Get Subscription Configuration Source: https://github.com/sub-store-org/sub-store/blob/master/_autodocs/endpoints.md Retrieves the configuration details for a specific subscription, including its name, URL, source, merge strategy, and enabled status. ```HTTP GET /api/sub/:name ``` -------------------------------- ### Create Subscription Request Body Source: https://github.com/sub-store-org/sub-store/blob/master/_autodocs/endpoints.md Example JSON structure for the request body when creating a new subscription, specifying required fields like 'name' and 'url', and optional configuration. ```JSON { name: string, // Required url: string, // Required source: string, // 'local' or 'remote' mergeSources: string, subUserinfo: string, proxy: string, ua: string, includeUnsupportedProxy: boolean, enabled: boolean, updateInterval: number } ``` -------------------------------- ### Join Raw File Content Example Source: https://github.com/sub-store-org/sub-store/blob/master/_autodocs/api-reference/sync-utilities.md Demonstrates how to join multiple file contents with newlines using the `joinRawFileContent` function. This function filters out null, undefined, and empty strings before joining. ```javascript joinRawFileContent(['line1', 'line2', null, 'line3']) // Returns: 'line1\nline2\nline3' ``` -------------------------------- ### REST API: Get Subscription Source: https://github.com/sub-store-org/sub-store/blob/master/_autodocs/README.md Retrieves subscription details from the API by making a GET request to the specified endpoint. ```bash # Get subscription curl http://localhost:3000/api/sub/my-sub ``` -------------------------------- ### Subscription Flow Info Response Source: https://github.com/sub-store-org/sub-store/blob/master/_autodocs/endpoints.md Example JSON response structure for subscription flow information, detailing download, upload, total data, expiration, and usage percentage. ```JSON { download: number, // Bytes downloaded upload: number, // Bytes uploaded total: number, // Total bytes allowed expire: number, // Unix timestamp of expiration remainingDays: number, usedPercent: number } ``` -------------------------------- ### Example of Parsing Flow Headers Source: https://github.com/sub-store-org/sub-store/blob/master/_autodocs/api-reference/download-utilities.md Demonstrates how to use the parseFlowHeaders function with a sample subscription user info string. The output shows the parsed flow details, including remaining days and used percentage. ```javascript const header = 'upload=1024; download=2048; total=10240; expire=1234567890'; const flow = parseFlowHeaders(header); // Returns: { // upload: 1024, // download: 2048, // total: 10240, // expire: 1234567890, // remainingDays: 5, // usedPercent: 30 // } ``` -------------------------------- ### List All Files Source: https://github.com/sub-store-org/sub-store/blob/master/_autodocs/endpoints.md Lists all files available in the system. Returns an array of file objects with basic metadata. ```http GET /api/files ``` -------------------------------- ### Get Current Sub-Store Settings via API Source: https://github.com/sub-store-org/sub-store/blob/master/_autodocs/configuration.md Retrieve the current persistent settings for Sub-Store using a GET request to the /api/settings endpoint. The response includes all configured settings. ```javascript GET /api/settings Response: { username: string, gistToken: string, syncPlatform: string, defaultTimeout: number, defaultProxy: string, // ... (all settings fields) } ``` -------------------------------- ### Initialize Data Store with Defaults Source: https://github.com/sub-store-org/sub-store/blob/master/_autodocs/api-reference/openapi-class.md Ensures a data store key exists, initializing it with an empty object if it's not found. ```javascript const SUBS_KEY = 'subs'; if (!$.read(SUBS_KEY)) { $.write({}, SUBS_KEY); } ``` -------------------------------- ### Make an HTTP GET Request Source: https://github.com/sub-store-org/sub-store/blob/master/_autodocs/api-reference/openapi-class.md The $.http.get() method facilitates making HTTP GET requests. It returns a Promise with the response status, body, and headers. Ensure to handle potential non-200 status codes. ```javascript const response = await $.http.get({ url: 'https://example.com/sub', headers: { 'User-Agent': 'Sub-Store/2.32.1' }, timeout: 10000 }); if (response.status === 200) { const body = response.body; } ``` -------------------------------- ### Build Project with esbuild Source: https://github.com/sub-store-org/sub-store/blob/master/README.md Bundles the project using esbuild for production or distribution. ```bash pnpm bundle:esbuild ``` -------------------------------- ### Get All Subscriptions Source: https://github.com/sub-store-org/sub-store/blob/master/_autodocs/endpoints.md Retrieves a list of all available subscriptions. ```APIDOC ## GET /api/subs ### Description Lists all subscriptions. ### Method GET ### Endpoint /api/subs ### Response #### Success Response (200) An array of subscription objects. ### Response Example ```json [ { "name": "sub1", "url": "http://example.com/sub1.txt" }, { "name": "sub2", "url": "http://example.com/sub2.txt" } ] ``` ``` -------------------------------- ### Get File (Whole) Source: https://github.com/sub-store-org/sub-store/blob/master/_autodocs/endpoints.md Retrieves a specific file with its complete content. ```APIDOC ## GET /api/wholeFile/:name ### Description Gets a file with full content. ### Method GET ### Endpoint /api/wholeFile/:name ### Parameters #### Path Parameters - **name** (string) - Required - File name ### Response #### Success Response (200) Complete file object #### Error Response - **404**: File not found ``` -------------------------------- ### Create File Source: https://github.com/sub-store-org/sub-store/blob/master/_autodocs/endpoints.md Creates a new file with the provided details. ```APIDOC ## POST /api/files ### Description Creates a new file. ### Method POST ### Endpoint /api/files ### Request Body { name: string, type: string, content: string, url: string, source: string, sourceType: string, sourceName: string } ### Response #### Success Response (201) Created file ``` -------------------------------- ### Get All Collections Source: https://github.com/sub-store-org/sub-store/blob/master/_autodocs/endpoints.md Retrieves a list of all available collections within the system. ```APIDOC ## GET /api/collections ### Description Lists all collections. ### Method GET ### Endpoint /api/collections ### Response #### Success Response (200) - Array of collection objects, each containing at least a 'name' and 'subscriptions' field. ``` -------------------------------- ### Importing the OpenAPI Instance Source: https://github.com/sub-store-org/sub-store/blob/master/_autodocs/api-reference/openapi-class.md Import the global OpenAPI instance provided by the application. This instance is pre-initialized for the 'sub-store' context. ```javascript import $ from '@/core/app'; // $ is a global OpenAPI instance initialized for 'sub-store' ``` -------------------------------- ### Get All Subscriptions Source: https://github.com/sub-store-org/sub-store/blob/master/_autodocs/endpoints.md Lists all available subscriptions. The response is an array of subscription objects. ```HTTP GET /api/subs ``` -------------------------------- ### REST API: Download Subscription in Clash Format Source: https://github.com/sub-store-org/sub-store/blob/master/_autodocs/README.md Initiates a download of a specific subscription in the Clash configuration format via the API. ```bash # Download in Clash format curl http://localhost:3000/download/my-sub/Clash ``` -------------------------------- ### Get Share Token Source: https://github.com/sub-store-org/sub-store/blob/master/_autodocs/endpoints.md Generates a share token for a subscription or collection, allowing for temporary access. ```APIDOC ## GET /api/token ### Description Generates a share token for a subscription/collection. ### Method GET ### Endpoint /api/token ### Parameters #### Query Parameters - **path** (string) - Required - API path to share (e.g., '/api/subs') - **expire** (number) - Optional - Token expiration time in milliseconds ### Response #### Success Response (200) - **token** (string) - The generated share token. - **expire** (number) - The expiration time of the token in milliseconds. - **path** (string) - The API path associated with the token. #### Response Example ```json { "token": "your_share_token", "expire": 1678886400000, "path": "/api/subs" } ``` ``` -------------------------------- ### Download Content with Options Source: https://github.com/sub-store-org/sub-store/blob/master/_autodocs/api-reference/download-utilities.md Use the download function to fetch content from a URL. Supports custom User-Agents, timeouts, proxies, caching strategies, and preprocessing. ```javascript const content = await download( 'https://example.com/sub' ); ``` ```javascript const content = await download( 'https://example.com/sub', 'MyApp/1.0' // Custom User-Agent ); ``` ```javascript const content = await download( 'https://example.com/sub', 'MyApp/1.0', 10000, // 10 second timeout 'http://proxy.local:8080' // HTTP proxy ); ``` ```javascript const content = await download( 'https://example.com/sub', undefined, undefined, undefined, true // skipCustomCache ); ``` ```javascript const content = await download( 'https://example.com/sub', undefined, undefined, undefined, false, false, true // noCache - don't cache result ); ``` ```javascript const content = await download( 'https://example.com/clash.yaml', undefined, undefined, undefined, false, false, false, true // preprocess ); ``` -------------------------------- ### Get Node Info Source: https://github.com/sub-store-org/sub-store/blob/master/_autodocs/endpoints.md Retrieves information about the current node, including its environment, version, and platform. ```APIDOC ## GET /api/node-info ### Description Returns information about the current node (platform, version, etc.). ### Method GET ### Endpoint /api/node-info ### Response #### Success Response (200) - **env** (string) - The environment of the node (e.g., 'node', 'qx', 'loon', 'surge'). - **version** (string) - The version of the node. - **platform** (string) - The platform of the node. #### Response Example ```json { "env": "node", "version": "1.0.0", "platform": "linux" } ``` ``` -------------------------------- ### Configure GitHub Proxy Acceleration Source: https://github.com/sub-store-org/sub-store/blob/master/_autodocs/api-reference/download-utilities.md Configure Sub-Store to route GitHub URLs through a proxy by specifying the proxy base URL and a regex to match the target GitHub hostnames. ```javascript { githubProxy: 'https://mirror.example.com', // Base URL of proxy githubProxyRegex: 'raw\.githubusercontent\.com' // Regex to match } ``` -------------------------------- ### Get Single Artifact Source: https://github.com/sub-store-org/sub-store/blob/master/_autodocs/endpoints.md Retrieves a specific artifact by its name. Returns a 404 if the artifact is not found. ```HTTP GET /api/artifact/:name ``` -------------------------------- ### Configuration Source: https://github.com/sub-store-org/sub-store/blob/master/_autodocs/README.md Details the configuration options for Sub-Store, including environment variables, persistent settings, and security configurations. ```APIDOC ## Configuration Information on how to configure Sub-Store. ### Configuration Areas: - Environment variables - Persistent settings schema - AGE encryption setup - CORS, caching, concurrency control - Default values and validation See `configuration.md` for comprehensive details. ``` -------------------------------- ### Get File Source: https://github.com/sub-store-org/sub-store/blob/master/_autodocs/endpoints.md Downloads a file with optional processing. Supports fetching by name or via a remote URL. ```APIDOC ## GET /api/file/:name ## GET /share/file/:name ### Description Downloads a file with optional processing. ### Method GET ### Endpoint /api/file/:name /share/file/:name ### Parameters #### Path Parameters - **name** (string) - Required - File name #### Query Parameters - **url** (string) - Optional - Remote file URL - **content** (string) - Optional - Inline file content - **mergeSources** (string) - Optional - Merge strategy - **includeUnsupportedProxy** (boolean) - Optional - Include unsupported proxies - **type** (string) - Optional - File type - **source** (string) - Optional - Source type - **sourceType** (string) - Optional - 'collection' | 'subscription' | 'local' | 'remote' - **sourceName** (string) - Optional - Source collection/subscription name - **mode** (string) - Optional - Processing mode - **ua** (string) - Optional - Custom User-Agent - **noCache** (boolean) - Optional - Skip caching - **produceType** (string) - Optional - Output type - **download** (boolean) - Optional - Force download - **fakeFile** (boolean) - Optional - Return fake file structure ### Response File content (text/plain or application/json) #### Success Response (200) Success #### Error Response - **404**: File not found - **400**: Invalid request ``` -------------------------------- ### Produce Proxy Configurations for Target Platforms Source: https://github.com/sub-store-org/sub-store/blob/master/_autodocs/api-reference/proxy-utils.md Converts an array of parsed proxy objects into a string format suitable for a specified target platform. Supports numerous platforms like Clash, Surge, QX, and V2Ray. ```javascript const proxies = ProxyUtils.parse(rawInput); const output = await ProxyUtils.produce(proxies, 'Clash', { noFlowHeaders: false, subUserinfo: 'expire=1234567890' }); // Returns Clash YAML format ``` -------------------------------- ### Get All Artifacts Source: https://github.com/sub-store-org/sub-store/blob/master/_autodocs/endpoints.md Lists all artifacts, which are remote sync targets. This endpoint returns an array of artifact objects. ```APIDOC ## GET /api/artifacts ### Description Lists all artifacts (remote sync targets). ### Method GET ### Endpoint /api/artifacts ### Response #### Success Response (200) - **name** (string) - **url** (string) - **type** (string) - 'subscription' | 'collection' | 'file' - **source** (string) - **platform** (string) - **sync** (string) - 'auto' | 'manual' - **syncInterval** (number) - **syncPlatform** (string) - 'github' | 'gitlab' - **syncNotification** (boolean) - **agePublicKey** (string) - **cron** (string) ### Response Example { "example": "[ { name: string, url: string, type: string, source: string, platform: string, sync: string, syncInterval: number, syncPlatform: string, syncNotification: boolean, agePublicKey: string, cron: string }, // ... ]" } ``` -------------------------------- ### Map sub.store to Localhost Source: https://github.com/sub-store-org/sub-store/blob/master/README.md To prevent accidental access to the public sub.store service, map it to a local address like 127.0.0.1 in your host file. ```ini [Host] sub.store = 127.0.0.1 ``` -------------------------------- ### Get Flow Info Source: https://github.com/sub-store-org/sub-store/blob/master/_autodocs/endpoints.md Retrieves subscription flow information, such as data usage, expiration, and remaining quota. ```APIDOC ## GET /api/sub/flow/:name ### Description Retrieves subscription flow information (data usage, expiration, etc.). ### Method GET ### Endpoint /api/sub/flow/:name ### Parameters #### Path Parameters - **name** (string) - Required - Subscription name #### Query Parameters - **url** (string) - Optional - Optional override subscription URL ### Response #### Success Response (200) - **download** (number) - Bytes downloaded - **upload** (number) - Bytes uploaded - **total** (number) - Total bytes allowed - **expire** (number) - Unix timestamp of expiration - **remainingDays** (number) - Days remaining - **usedPercent** (number) - Percentage used ### Response Example ```json { "download": 1024, "upload": 512, "total": 1048576, "expire": 1678886400, "remainingDays": 10, "usedPercent": 0.1 } ``` ### Errors - `ResourceNotFoundError` (404): Subscription does not exist - `RequestInvalidError` (400): No flow information available or parse error ``` -------------------------------- ### Run Tests Source: https://github.com/sub-store-org/sub-store/blob/master/_autodocs/README.md Execute the test suite using pnpm. Tests are located in the src/test/**/*.spec.js directory. ```bash # Run tests pnpm test # Tests located in src/test/**/*.spec.js ``` -------------------------------- ### Get Application Logs Source: https://github.com/sub-store-org/sub-store/blob/master/_autodocs/endpoints.md Retrieves application logs. You can filter logs by level and specify the maximum count to return. ```http GET /api/logs ``` -------------------------------- ### Get Collection Source: https://github.com/sub-store-org/sub-store/blob/master/_autodocs/endpoints.md Retrieves a specific collection's configuration by its name. Supports downloading the collection as a JSON file. ```APIDOC ## GET /api/collection/:name ### Description Retrieves a collection configuration. ### Method GET ### Endpoint /api/collection/:name ### Parameters #### Path Parameters - **name** (string) - Required - Collection name #### Query Parameters - **raw** (boolean) - Optional - Download as JSON file ### Response #### Success Response (200) - **name** (string) - **subscriptions** (string[]) - Array of subscription names - **excludeSubscriptions** (string[]) - **operators** (Array) - **content** (string) - **mergeSources** (string) - 'merge' | 'localFirst' | 'remoteFirst' #### Response Example ```json { "name": "string", "subscriptions": ["string"], "excludeSubscriptions": ["string"], "operators": [], "content": "string", "mergeSources": "merge" } ``` ``` -------------------------------- ### Create Subscription Source: https://github.com/sub-store-org/sub-store/blob/master/_autodocs/endpoints.md Creates a new subscription with the provided configuration. ```APIDOC ## POST /api/subs ### Description Creates a new subscription. ### Method POST ### Endpoint /api/subs ### Parameters #### Request Body - **name** (string) - Required - **url** (string) - Required - **source** (string) - Optional - 'local' or 'remote' - **mergeSources** (string) - Optional - **subUserinfo** (string) - Optional - **proxy** (string) - Optional - **ua** (string) - Optional - **includeUnsupportedProxy** (boolean) - Optional - **enabled** (boolean) - Optional - **updateInterval** (number) - Optional ### Request Example ```json { "name": "new-sub", "url": "http://example.com/new.txt", "source": "remote", "enabled": true } ``` ### Response #### Success Response (201) Created subscription object ### Response Example ```json { "name": "new-sub", "url": "http://example.com/new.txt", "source": "remote", "mergeSources": "merge", "subUserinfo": "", "proxy": "", "ua": "", "includeUnsupportedProxy": false, "enabled": true, "updateInterval": 30 } ``` ### Errors - `RequestInvalidError`: Invalid subscription data ```