mirror of
https://github.com/unraid/api.git
synced 2026-01-04 15:39:52 -06:00
- **New Features** - Created a dynamic plugin system for the API to enable community augmentation of GraphQL, CLI, and Cron functionalities capabilities. - Included an example plugin under `packages/unraid-api-plugin-health` that adds a new graphql query for API health checks. - Added `rc.unraid-api` commands for backing up, restoring, and installing production dependencies, streamlining maintenance and deployment. - Improved dependency vendoring by bundling a versioned pnpm store (instead of `node_modules`). Versioning will allow users to add plugins to a specific api release without requiring an internet connection on subsequent reboots. - **Chores** - Upgraded build workflows and versioning processes to ensure more reliable artifact handling and production packaging.
51 lines
1.5 KiB
TypeScript
51 lines
1.5 KiB
TypeScript
import { getTxzName, LOCAL_BUILD_TAG, pluginNameWithExt } from "./consts";
|
|
|
|
// Define a common interface for URL parameters
|
|
interface UrlParams {
|
|
baseUrl: string;
|
|
tag?: string;
|
|
}
|
|
|
|
interface TxzUrlParams extends UrlParams {
|
|
pluginVersion: string;
|
|
}
|
|
|
|
/**
|
|
* Get the bucket path for the given tag
|
|
* ex. baseUrl = https://stable.dl.unraid.net/unraid-api
|
|
* ex. tag = PR123
|
|
* ex. returns = https://stable.dl.unraid.net/unraid-api/tag/PR123
|
|
*/
|
|
const getRootBucketPath = ({ baseUrl, tag }: UrlParams): URL => {
|
|
// Append tag to the baseUrl if tag is set, otherwise return the baseUrl
|
|
const url = new URL(baseUrl);
|
|
if (tag && tag !== LOCAL_BUILD_TAG) {
|
|
// Ensure the path ends with a trailing slash before adding the tag
|
|
url.pathname = url.pathname.replace(/\/?$/, "/") + "tag/" + tag;
|
|
}
|
|
return url;
|
|
};
|
|
|
|
/**
|
|
* Get the URL for an asset from the root bucket
|
|
* ex. returns = BASE_URL/TAG/dynamix.unraid.net.plg
|
|
*/
|
|
export const getAssetUrl = (params: UrlParams, assetName: string): string => {
|
|
const rootUrl = getRootBucketPath(params);
|
|
rootUrl.pathname = rootUrl.pathname.replace(/\/?$/, "/") + assetName;
|
|
return rootUrl.toString();
|
|
};
|
|
/**
|
|
* Get the URL for the plugin file
|
|
* ex. returns = BASE_URL/TAG/dynamix.unraid.net.plg
|
|
*/
|
|
export const getPluginUrl = (params: UrlParams): string =>
|
|
getAssetUrl(params, pluginNameWithExt);
|
|
|
|
/**
|
|
* Get the URL for the main TXZ file
|
|
* ex. returns = BASE_URL/TAG/dynamix.unraid.net-4.1.3.txz
|
|
*/
|
|
export const getMainTxzUrl = (params: TxzUrlParams): string =>
|
|
getAssetUrl(params, getTxzName(params.pluginVersion));
|