2025-03-10 12:13:58 +00:00
|
|
|
export interface CacheRoot {
|
2025-05-24 12:07:53 +00:00
|
|
|
retainers: Record<string, CacheRetainer>;
|
2025-03-10 12:13:58 +00:00
|
|
|
items: Record<string, CacheMetadata>;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export const EMPTY_CACHE_ROOT: CacheRoot = {
|
2025-05-24 12:07:53 +00:00
|
|
|
retainers: {},
|
2025-03-10 12:13:58 +00:00
|
|
|
items: {},
|
|
|
|
|
}
|
|
|
|
|
|
2025-05-24 12:07:53 +00:00
|
|
|
/**
|
2025-03-10 12:13:58 +00:00
|
|
|
* All files that reference a {@link CacheMetadata}.
|
|
|
|
|
* The cache should only be remove when there are no "retainers".
|
|
|
|
|
*/
|
|
|
|
|
export interface CacheRetainer {
|
|
|
|
|
/** Cache items referenced, i.e., retained. */
|
|
|
|
|
ref: string[];
|
|
|
|
|
}
|
2025-03-07 04:57:00 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* - All datetimes are stored in ISO 8601, e.g., "2023-10-27T10:30:00Z".
|
|
|
|
|
*/
|
|
|
|
|
export interface CacheMetadata {
|
2025-03-10 12:13:58 +00:00
|
|
|
ty: CacheType;
|
|
|
|
|
|
|
|
|
|
f: CacheMetadataFile;
|
|
|
|
|
|
|
|
|
|
i?: CacheMetadataImage;
|
|
|
|
|
|
|
|
|
|
ti: CacheMetadataTime;
|
2025-03-07 04:57:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export const enum CacheType {
|
|
|
|
|
UNDEFINED = 0,
|
|
|
|
|
IMAGE = 1,
|
|
|
|
|
};
|
|
|
|
|
|
2025-03-10 12:13:58 +00:00
|
|
|
/** Common things about a file and its content. */
|
2025-03-07 04:57:00 +00:00
|
|
|
export interface CacheMetadataFile {
|
2025-03-10 12:13:58 +00:00
|
|
|
/** src */
|
|
|
|
|
s: string;
|
|
|
|
|
|
|
|
|
|
/** name */
|
|
|
|
|
n: string;
|
|
|
|
|
|
2025-05-24 12:07:53 +00:00
|
|
|
/**
|
2025-03-10 12:13:58 +00:00
|
|
|
* ext
|
2025-05-24 12:07:53 +00:00
|
|
|
* If empty string, then no extension.
|
2025-03-10 12:13:58 +00:00
|
|
|
*/
|
|
|
|
|
e: string;
|
|
|
|
|
|
|
|
|
|
/** size in bytes */
|
|
|
|
|
sz: number;
|
2025-03-07 04:57:00 +00:00
|
|
|
|
|
|
|
|
/**
|
2025-03-10 12:13:58 +00:00
|
|
|
* Content-Type from the HTTP response header.
|
2025-03-07 04:57:00 +00:00
|
|
|
*/
|
|
|
|
|
ct?: string;
|
|
|
|
|
|
2025-03-10 12:13:58 +00:00
|
|
|
/** xxHash of the file's content. */
|
|
|
|
|
ch: string;
|
2025-03-07 04:57:00 +00:00
|
|
|
}
|
|
|
|
|
|
2025-03-10 12:13:58 +00:00
|
|
|
/** Image specific */
|
2025-03-07 04:57:00 +00:00
|
|
|
export interface CacheMetadataImage {
|
2025-03-10 12:13:58 +00:00
|
|
|
w: number;
|
|
|
|
|
h: number;
|
2025-03-07 04:57:00 +00:00
|
|
|
/** Type as parsed from image data by [image-size](https://github.com/image-size/image-size). If empty string, then not determined. */
|
2025-03-10 12:13:58 +00:00
|
|
|
t: string;
|
2025-03-07 04:57:00 +00:00
|
|
|
}
|
|
|
|
|
|
2025-03-10 12:13:58 +00:00
|
|
|
/** Time related */
|
2025-03-07 04:57:00 +00:00
|
|
|
export interface CacheMetadataTime {
|
2025-05-24 12:07:53 +00:00
|
|
|
|
2025-03-10 12:13:58 +00:00
|
|
|
/** Download time */
|
|
|
|
|
d: string;
|
2025-05-24 12:07:53 +00:00
|
|
|
|
2026-04-28 04:14:11 +00:00
|
|
|
/**
|
|
|
|
|
* "Last time checked".
|
|
|
|
|
*
|
|
|
|
|
* Currently set to download time and never updated.
|
|
|
|
|
* @todo May be used to keep track of when the server was last checked for modified.
|
|
|
|
|
*/
|
2025-03-10 12:13:58 +00:00
|
|
|
l: string;
|
|
|
|
|
|
|
|
|
|
/** Value of the `Cache-Control` HTTP response header. */
|
|
|
|
|
cc?: string;
|
2026-04-28 04:14:11 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Value of the `ETag` HTTP response header.
|
|
|
|
|
*
|
|
|
|
|
* In the HTTP spec (RFC 7232), an ETag must be wrapped in double quotes. But here they are not. Add them back when using the ETag in requests.
|
|
|
|
|
*
|
|
|
|
|
* @since 1.1.1
|
|
|
|
|
*/
|
|
|
|
|
et?: string;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Normalized value of the `Last-Modified` HTTP response header (ISO 8601).
|
|
|
|
|
*
|
|
|
|
|
* Converted from HTTP-date format to ISO for consistency. Convert back to UTC string when using in 'If-Modified-Since' headers.
|
|
|
|
|
*
|
|
|
|
|
* @since 1.1.1
|
|
|
|
|
*/
|
|
|
|
|
m?: string;
|
2025-05-24 12:07:53 +00:00
|
|
|
}
|