astronaut-cms 0.0.1 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +84 -3
- package/dist/admin/THIRD_PARTY_LICENSES.md +7646 -0
- package/dist/admin/assets/assistant-DTlSNidc.js +235 -0
- package/dist/admin/assets/badge-BfN73-be.js +1 -0
- package/dist/admin/assets/changes-h1lmD7AA.js +1 -0
- package/dist/admin/assets/client-B4PWCmC4.js +5 -0
- package/dist/admin/assets/clsx-DB0hHKMi.js +1 -0
- package/dist/admin/assets/collapsible-item-zlnNAUdM.js +1 -0
- package/dist/admin/assets/collapsible-mcJ6G3X4.js +1 -0
- package/dist/admin/assets/collections._collection-D-rC9E9v.js +1 -0
- package/dist/admin/assets/collections._collection._entry-UD8hLmC1.js +52 -0
- package/dist/admin/assets/collections._collection.index-Cgc93hCD.js +1 -0
- package/dist/admin/assets/component-lookup-8lVQh8pl.js +4 -0
- package/dist/admin/assets/config-Pm_BHLNT.js +1 -0
- package/dist/admin/assets/copy-DxuErr3x.js +1 -0
- package/dist/admin/assets/css-BGIxQoYs.js +1 -0
- package/dist/admin/assets/css-DgaLhXQH.js +1 -0
- package/dist/admin/assets/diff-woXpYk--.js +1 -0
- package/dist/admin/assets/dist-DVv3ALC7.js +1 -0
- package/dist/admin/assets/dist-Dpyc1riS.js +1 -0
- package/dist/admin/assets/docx-BctAmX91.js +56 -0
- package/dist/admin/assets/editor-BauN0yXd.js +2 -0
- package/dist/admin/assets/empty-DAOUBpWb.js +1 -0
- package/dist/admin/assets/entry-link-DhcL6M5c.js +158 -0
- package/dist/admin/assets/error-banner-CNWZU5u_.js +161 -0
- package/dist/admin/assets/errors-DkJ5E_ak.js +1 -0
- package/dist/admin/assets/field-CbbZZGxO.js +41 -0
- package/dist/admin/assets/field-schema-CacrjSYw.js +1 -0
- package/dist/admin/assets/file-text-Ciz5Mr4S.js +1 -0
- package/dist/admin/assets/github-dark-C-LZuMrd.js +1 -0
- package/dist/admin/assets/github-light-EUqPIrTm.js +1 -0
- package/dist/admin/assets/highlighted-body-JLMTFACH-D1bycIV3.js +1 -0
- package/dist/admin/assets/html-CvFb5cGI.js +1 -0
- package/dist/admin/assets/javascript-BzbQS41l.js +1 -0
- package/dist/admin/assets/javascript-CpIGwZ_Y.js +1 -0
- package/dist/admin/assets/json-qhed-kSA.js +1 -0
- package/dist/admin/assets/jsx-Bz0zcwM4.js +1 -0
- package/dist/admin/assets/lib-CC_S4yjQ.js +21 -0
- package/dist/admin/assets/library-Da82FNwp.js +1 -0
- package/dist/admin/assets/list-skeleton-BXLP4Fak.js +1 -0
- package/dist/admin/assets/markdown-BYOwaDjH.js +1 -0
- package/dist/admin/assets/matchContext-BjW1F-Cq.js +2 -0
- package/dist/admin/assets/media-browser-DeKpWCUD.js +1 -0
- package/dist/admin/assets/media._library-DGnXJc0I.js +1 -0
- package/dist/admin/assets/mermaid-WFAXDIZX-CqFnahFh.js +1 -0
- package/dist/admin/assets/page-header-C2Uwa_yv.js +1 -0
- package/dist/admin/assets/pdf-BSEX-sd8.js +106 -0
- package/dist/admin/assets/python-gzcpVVnB.js +1 -0
- package/dist/admin/assets/react-CXnqG51l.js +1 -0
- package/dist/admin/assets/rolldown-runtime-BWaJ3C7D.js +1 -0
- package/dist/admin/assets/routes-Bx9rPcHA.js +1 -0
- package/dist/admin/assets/routes-D7tEdYGV.js +1 -0
- package/dist/admin/assets/save-actions-DrVgh3KH.js +32 -0
- package/dist/admin/assets/select-CMV39q80.js +1 -0
- package/dist/admin/assets/separator-C9bNKNSU.js +3 -0
- package/dist/admin/assets/shell-DBEiq06l.js +1 -0
- package/dist/admin/assets/shellscript-CLZ0U2zV.js +1 -0
- package/dist/admin/assets/skeleton-DTwTUSqm.js +1 -0
- package/dist/admin/assets/sql-CEbI0hMM.js +1 -0
- package/dist/admin/assets/syntax-DDPd1mQn.js +8 -0
- package/dist/admin/assets/toggle-B6ASf-kL.js +1 -0
- package/dist/admin/assets/toml-BPTmHmyx.js +1 -0
- package/dist/admin/assets/tsx-udAQXfEw.js +1 -0
- package/dist/admin/assets/typescript-bsJCZSQ-.js +1 -0
- package/dist/admin/assets/ui.module.css-BdAmwQeM.js +56 -0
- package/dist/admin/assets/use-entries-CrNqaMfa.js +1 -0
- package/dist/admin/assets/useSelector-Cs39W18m.js +1 -0
- package/dist/admin/assets/yaml-rwi0_p6S.js +1 -0
- package/dist/admin/assets/zwitch-Wwuax-dJ.js +1 -0
- package/dist/admin/bootstrap.d.ts +1 -0
- package/dist/admin/bootstrap.js +1 -0
- package/dist/admin/editor.d.ts +1065 -0
- package/dist/admin/editor.js +1 -0
- package/dist/server/THIRD_PARTY_LICENSES.md +49 -0
- package/dist/server/assets.d.ts +30 -0
- package/dist/server/assets.js +30 -0
- package/dist/server/chunks/anchors-DuZ1fokt.js +86 -0
- package/dist/server/chunks/auth-DJP9ryVd.js +44 -0
- package/dist/server/chunks/cms-markers-CUqrOnfA.js +78 -0
- package/dist/server/chunks/component-lookup-DAFg_Qg8.js +128 -0
- package/dist/server/chunks/config-BsOYly9a.d.ts +1210 -0
- package/dist/server/chunks/digest-tkKu_Wj5.js +753 -0
- package/dist/server/chunks/entry-checks-3SxhoHwH.js +608 -0
- package/dist/server/chunks/field-schema-CfdN75jT.js +48 -0
- package/dist/server/chunks/http-BnsNh57m.d.ts +35 -0
- package/dist/server/chunks/i18n-BPmx7ESy.d.ts +15 -0
- package/dist/server/chunks/index-CYbkNvu5.d.ts +22 -0
- package/dist/server/chunks/media-BhqUVVYY.js +223 -0
- package/dist/server/chunks/paths-CEW9fvg8.js +17 -0
- package/dist/server/chunks/paths-Dztx2eUw.js +13 -0
- package/dist/server/chunks/types-DkkewFTT.js +418 -0
- package/dist/server/chunks/types-Dkx4Xovf.d.ts +359 -0
- package/dist/server/chunks/types-Jew_-Qpp.d.ts +273 -0
- package/dist/server/chunks/user-config-CqNK-Ebs.js +292 -0
- package/dist/server/chunks/xml-D8qPILJU.js +81 -0
- package/dist/server/config.d.ts +3 -0
- package/dist/server/config.js +22 -0
- package/dist/server/content.d.ts +58 -0
- package/dist/server/content.js +83 -0
- package/dist/server/endpoint.d.ts +16 -0
- package/dist/server/endpoint.js +2726 -0
- package/dist/server/integration.d.ts +7 -0
- package/dist/server/integration.js +1187 -0
- package/dist/server/internal.d.ts +100 -0
- package/dist/server/internal.js +30 -0
- package/dist/server/server-local.d.ts +453 -0
- package/dist/server/server-local.js +336 -0
- package/dist/styles/THIRD_PARTY_LICENSES.md +193 -0
- package/dist/styles/assets/geist-cyrillic-ext-wght-normal-DjL33-gN.woff2 +0 -0
- package/dist/styles/assets/geist-cyrillic-wght-normal-BEAKL7Jp.woff2 +0 -0
- package/dist/styles/assets/geist-latin-ext-wght-normal-DC-KSUi6.woff2 +0 -0
- package/dist/styles/assets/geist-latin-wght-normal-BgDaEnEv.woff2 +0 -0
- package/dist/styles/assets/geist-vietnamese-wght-normal-6IgcOCM7.woff2 +0 -0
- package/dist/styles/styles.css +3 -0
- package/package.json +151 -5
- package/src/astro/Image.astro +28 -0
- package/src/astro/Video.astro +44 -0
- package/src/astro/admin.astro +137 -0
- package/src/astro/licenses.ts +5 -0
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The one place the localized-entry convention lives: a localized collection
|
|
3
|
+
* stores every entry under a leading locale segment (`en/about`, `de/about`),
|
|
4
|
+
* the layout Astro's own i18n recipe recommends. The rest of the id is shared
|
|
5
|
+
* across translations, which is what lets the admin pair them up.
|
|
6
|
+
*
|
|
7
|
+
* The admin UI and the AI assistant both derive every locale decision from these
|
|
8
|
+
* helpers, so the convention is never restated (and cannot drift) at a second site.
|
|
9
|
+
*/
|
|
10
|
+
/** The site's content languages, mirrored from `astro.config`'s own `i18n`. */
|
|
11
|
+
interface ContentI18n {
|
|
12
|
+
locales: string[];
|
|
13
|
+
defaultLocale: string;
|
|
14
|
+
}
|
|
15
|
+
export { ContentI18n as t };
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { ImageMetadata } from "astro";
|
|
2
|
+
/**
|
|
3
|
+
* Filled in for each site by the types the integration generates, with whether
|
|
4
|
+
* it configures an object store. Empty where those types are not loaded.
|
|
5
|
+
*/
|
|
6
|
+
interface MediaRegistry {}
|
|
7
|
+
/**
|
|
8
|
+
* What {@link resolveImage} returns: always image metadata for a site with only
|
|
9
|
+
* the repository library, and a URL for an object-store file too.
|
|
10
|
+
*/
|
|
11
|
+
type ResolvedImage = MediaRegistry extends {
|
|
12
|
+
s3: false;
|
|
13
|
+
} ? ImageMetadata : ImageMetadata | string;
|
|
14
|
+
/**
|
|
15
|
+
* Resolve an asset reference to optimized image metadata, or, for an
|
|
16
|
+
* object-store file, to the URL the image is served under. Absolute paths need
|
|
17
|
+
* no `base`, relative paths resolve against `base` (e.g. `entry.filePath`).
|
|
18
|
+
*/
|
|
19
|
+
declare const resolveImage: (path: string, base?: string) => Promise<ResolvedImage>;
|
|
20
|
+
/** Resolve an asset path to a file URL. See {@link resolveImage} for base semantics. */
|
|
21
|
+
declare const resolveFile: (path: string, base?: string) => Promise<string>;
|
|
22
|
+
export { resolveImage as i, ResolvedImage as n, resolveFile as r, MediaRegistry as t };
|
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
import "./paths-CEW9fvg8.js";
|
|
2
|
+
import { dirname, join } from "pathe";
|
|
3
|
+
import mime from "mime/lite";
|
|
4
|
+
// src/shared/url.ts
|
|
5
|
+
/**
|
|
6
|
+
* URL primitives shared by the server relays, the admin bundle and the build.
|
|
7
|
+
* Small enough to be tempting to re-write per call site, which is exactly why
|
|
8
|
+
* they live in one place: a join that disagrees about slashes produces a URL
|
|
9
|
+
* that resolves to the wrong thing rather than failing outright.
|
|
10
|
+
*/
|
|
11
|
+
var trimSlashes = (value) => value.replace(/^\/+|\/+$/g, "");
|
|
12
|
+
/** Drops one trailing slash, keeping a lone "/" as the root. */
|
|
13
|
+
var withoutTrailingSlash = (path) => path.replace(/\/$/, "") || "/";
|
|
14
|
+
var withTrailingSlash = (path) => path.endsWith("/") ? path : `${path}/`;
|
|
15
|
+
/** Joins URL segments with exactly one slash between each, keeping the last one's trailing slash. */
|
|
16
|
+
var joinUrl = (base, ...segments) => segments.reduce((url, segment) => !segment ? url : url ? withTrailingSlash(url) + segment.replace(/^\/+/, "") : segment, base);
|
|
17
|
+
/** Whether a value carries its own scheme rather than resolving against a base. */
|
|
18
|
+
var isAbsoluteUrl = (value) => URL.canParse(value);
|
|
19
|
+
/**
|
|
20
|
+
* Rewrites a URL path into the form the host site's `trailingSlash` policy makes
|
|
21
|
+
* Astro match. A mismatch either 404s (an injected API route) or fails to match
|
|
22
|
+
* the callback URL registered with the OAuth provider. "ignore" matches both.
|
|
23
|
+
*/
|
|
24
|
+
function conformTrailingSlash(rawUrl, policy) {
|
|
25
|
+
if (policy === "ignore") return rawUrl;
|
|
26
|
+
const url = new URL(rawUrl);
|
|
27
|
+
url.pathname = policy === "always" ? withTrailingSlash(url.pathname) : withoutTrailingSlash(url.pathname);
|
|
28
|
+
return url.href;
|
|
29
|
+
}
|
|
30
|
+
// src/shared/asset-path.ts
|
|
31
|
+
/**
|
|
32
|
+
* The single rule mapping a stored asset path to the key of the generated
|
|
33
|
+
* `virtual:astronaut-cms/assets` maps. The render-time resolver
|
|
34
|
+
* (`astronaut-cms/assets`) and the build-time content check both go through
|
|
35
|
+
* here, so a relative reference can never normalize one way in one place and
|
|
36
|
+
* another way in the other.
|
|
37
|
+
*
|
|
38
|
+
* Absolute paths are keys as-is; relative paths resolve against `base`'s
|
|
39
|
+
* directory. pathe is POSIX-normalized on every platform, matching Vite's
|
|
40
|
+
* forward-slash glob keys and handling "." / "..".
|
|
41
|
+
*/
|
|
42
|
+
function assetKey(path, base) {
|
|
43
|
+
if (path.startsWith("/")) return path;
|
|
44
|
+
if (!base) throw new Error(`Relative CMS asset path requires a base: ${path}`);
|
|
45
|
+
const baseDir = dirname(join("/", base));
|
|
46
|
+
return join(baseDir, path);
|
|
47
|
+
}
|
|
48
|
+
// src/shared/media.ts
|
|
49
|
+
/**
|
|
50
|
+
* How the media libraries are addressed. There are at most two: the repository
|
|
51
|
+
* library, always present, and an object store beside it. Backends speak
|
|
52
|
+
* library-relative paths, and content stores a reference that names the library
|
|
53
|
+
* by its shape: a project path (`/src/assets/logo.svg`) for the repository, the
|
|
54
|
+
* public URL (`https://cdn.example.com/photos/hero.png`) for the object store.
|
|
55
|
+
* The URL is what astro itself resolves as a remote image, in a collection
|
|
56
|
+
* `image()` field and a markdown body alike, so an object-store reference needs
|
|
57
|
+
* nothing of the CMS to render.
|
|
58
|
+
*/
|
|
59
|
+
var S3_ACCESS_KEY_ID_ENV = "ASTRONAUT_CMS_S3_ACCESS_KEY_ID";
|
|
60
|
+
var S3_SECRET_ACCESS_KEY_ENV = "ASTRONAUT_CMS_S3_SECRET_ACCESS_KEY";
|
|
61
|
+
var S3_SESSION_TOKEN_ENV = "ASTRONAUT_CMS_S3_SESSION_TOKEN";
|
|
62
|
+
/**
|
|
63
|
+
* Largest upload the server holds in memory when a library sets no limit of its
|
|
64
|
+
* own. GitHub refuses a file above this size anyway.
|
|
65
|
+
*/
|
|
66
|
+
var MAX_SERVER_UPLOAD_BYTES = 104857600;
|
|
67
|
+
/** The libraries this site has, the repository first. */
|
|
68
|
+
function mediaLibraries(media) {
|
|
69
|
+
return media.s3 ? ["repo", "s3"] : ["repo"];
|
|
70
|
+
}
|
|
71
|
+
/** A library this site has, as a route or a caller names it, or null. */
|
|
72
|
+
function parseMediaLibrary(media, value) {
|
|
73
|
+
return mediaLibraries(media).find((id) => id === value) ?? null;
|
|
74
|
+
}
|
|
75
|
+
/** The object store, which throws for a site that does not have one. */
|
|
76
|
+
function s3Library(media) {
|
|
77
|
+
if (!media.s3) throw new Error("No object-store media library is configured.");
|
|
78
|
+
return media.s3;
|
|
79
|
+
}
|
|
80
|
+
/** A library's own config, which throws for an object store the site does not have. */
|
|
81
|
+
function mediaLibrary(media, library) {
|
|
82
|
+
return library === "repo" ? media.repo : s3Library(media);
|
|
83
|
+
}
|
|
84
|
+
/** Every directory of the project a library keeps its bytes in. */
|
|
85
|
+
function libraryDirectories(media) {
|
|
86
|
+
return mediaLibraries(media).flatMap((id) => mediaLibrary(media, id).directory ?? []);
|
|
87
|
+
}
|
|
88
|
+
/** A size in English for the server's messages, the admin formats its own with `formatSize`. */
|
|
89
|
+
var megabytes = (bytes) => `${Math.round(bytes / 1024 / 1024 * 10) / 10} MB`;
|
|
90
|
+
/** Why a file of `size` bytes is refused by a library, or null when it fits. */
|
|
91
|
+
function sizeIssue(size, limits) {
|
|
92
|
+
if (limits.maxFileSize != null && size > limits.maxFileSize) return "tooLarge";
|
|
93
|
+
if (limits.minFileSize != null && size < limits.minFileSize) return "tooSmall";
|
|
94
|
+
return null;
|
|
95
|
+
}
|
|
96
|
+
/** The server's wording of a size refusal. */
|
|
97
|
+
function sizeLimitError(size, limits) {
|
|
98
|
+
switch (sizeIssue(size, limits)) {
|
|
99
|
+
case "tooLarge": return `File is larger than the ${megabytes(limits.maxFileSize ?? 0)} limit for this media library.`;
|
|
100
|
+
case "tooSmall": return `File is smaller than the ${megabytes(limits.minFileSize ?? 0)} minimum for this media library.`;
|
|
101
|
+
default: return null;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
/** Why a field astro types as an imported image refuses an object-store file. */
|
|
105
|
+
var repoOnlyRefusal = (value) => `"${value}" is an object-store file, but this field only takes repository files. Declare it with libraryImage(image) to accept both.`;
|
|
106
|
+
/** Enforced in the admin before sending, and again on the server, which is where it counts. */
|
|
107
|
+
function assertWithinSizeLimit(size, limits) {
|
|
108
|
+
const error = sizeLimitError(size, limits);
|
|
109
|
+
if (error) throw new Error(error);
|
|
110
|
+
}
|
|
111
|
+
var HIDDEN_SEGMENT = /(?:^|\/)\.[^./]/;
|
|
112
|
+
/**
|
|
113
|
+
* Whether a path is a library file: never a hidden one (`.DS_Store`, `.gitkeep`,
|
|
114
|
+
* the object store's `.trash/`), and of a configured type where the library is
|
|
115
|
+
* restricted to some. `null` admits any file.
|
|
116
|
+
*/
|
|
117
|
+
function isLibraryFile(path, extensions) {
|
|
118
|
+
if (HIDDEN_SEGMENT.test(path)) return false;
|
|
119
|
+
return extensions == null || hasAllowedExtension(path, extensions);
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Whether a path ends in one of `extensions`. The configured list is already
|
|
123
|
+
* lower-cased where the config is resolved, so a hot call, once per repository
|
|
124
|
+
* blob and once per path-shaped token in a body, lowers only the path.
|
|
125
|
+
*/
|
|
126
|
+
function hasAllowedExtension(path, extensions) {
|
|
127
|
+
const lower = path.toLowerCase();
|
|
128
|
+
return extensions.some((ext) => lower.endsWith(ext));
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* Each segment encoded: a key may hold a space or a `#`, which would otherwise
|
|
132
|
+
* address something other than the object the store actually holds. Shared by
|
|
133
|
+
* the public URL and by an S3 `CopySource`, which is parsed rather than decoded.
|
|
134
|
+
*/
|
|
135
|
+
var encodeKeyPath = (path) => trimSlashes(path).split("/").map(encodeURIComponent).join("/");
|
|
136
|
+
/** How a reference to the libraries reads, wherever one has to be explained. */
|
|
137
|
+
function describeMediaRef(media) {
|
|
138
|
+
const repo = `a path under the media directory ("/${trimSlashes(media.repo.directory)}/...")`;
|
|
139
|
+
return media.s3 ? `${repo} or a URL under "${media.s3.publicUrl}/"` : repo;
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* The library file an asset reference names, or null when the reference does not
|
|
143
|
+
* address a media library at all (a path outside the media directory, a URL
|
|
144
|
+
* under some other host). Callers treat null as "this value cannot resolve",
|
|
145
|
+
* which is exactly what it means at render time.
|
|
146
|
+
*
|
|
147
|
+
* `base` is the content file a relative reference is written in. Rebasing is a
|
|
148
|
+
* repository-library rule: an object-store reference is an absolute URL.
|
|
149
|
+
*/
|
|
150
|
+
function mediaPath(ref, media, base) {
|
|
151
|
+
if (isAbsoluteUrl(ref)) {
|
|
152
|
+
const key = media.s3 && publicKey(ref, media.s3.publicUrl);
|
|
153
|
+
return key ? {
|
|
154
|
+
library: "s3",
|
|
155
|
+
path: key
|
|
156
|
+
} : null;
|
|
157
|
+
}
|
|
158
|
+
const project = base && !ref.startsWith("/") ? assetKey(ref, base) : ref;
|
|
159
|
+
const prefix = `${trimSlashes(media.repo.directory)}/`;
|
|
160
|
+
const normalized = project.replace(/^\//, "");
|
|
161
|
+
return normalized.startsWith(prefix) ? {
|
|
162
|
+
library: "repo",
|
|
163
|
+
path: normalized.slice(prefix.length)
|
|
164
|
+
} : null;
|
|
165
|
+
}
|
|
166
|
+
/** The key a URL under the public base serves. Inverse of {@link remoteMediaUrl}. */
|
|
167
|
+
function publicKey(url, publicUrl) {
|
|
168
|
+
const location = URL.parse(url);
|
|
169
|
+
const base = URL.parse(`${publicUrl}/`);
|
|
170
|
+
if (!location || !base || location.origin !== base.origin || !location.pathname.startsWith(base.pathname)) return null;
|
|
171
|
+
try {
|
|
172
|
+
return decodeURIComponent(location.pathname.slice(base.pathname.length)) || null;
|
|
173
|
+
} catch {
|
|
174
|
+
return null;
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
/** Bucket URL for requests, including a custom endpoint's path. */
|
|
178
|
+
function s3BaseUrl(target) {
|
|
179
|
+
const url = new URL(target.endpoint);
|
|
180
|
+
if (target.pathStyle) url.pathname = joinUrl(url.pathname, target.bucket);
|
|
181
|
+
else url.hostname = `${target.bucket}.${url.hostname}`;
|
|
182
|
+
return url;
|
|
183
|
+
}
|
|
184
|
+
/** The public URL a library path is served under by a remote backend. */
|
|
185
|
+
function remoteMediaUrl(path, publicUrl) {
|
|
186
|
+
return joinUrl(publicUrl, encodeKeyPath(path));
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* The content type a file is stored with, decided from its extension rather than
|
|
190
|
+
* from what the uploader declares. A store serves back whatever type it was
|
|
191
|
+
* given, so letting the caller choose it is letting the caller choose how the
|
|
192
|
+
* bytes are interpreted. An extension the registry cannot name is stored as a
|
|
193
|
+
* generic download, which is the safe reading of a file the CMS cannot name.
|
|
194
|
+
*/
|
|
195
|
+
function mediaContentType(path) {
|
|
196
|
+
return mime.getType(path) ?? "application/octet-stream";
|
|
197
|
+
}
|
|
198
|
+
/**
|
|
199
|
+
* Whether a browser would run this type as a document, given the chance: HTML
|
|
200
|
+
* and every XML dialect, SVG among them. SVG is harmless in an `<img>`, which
|
|
201
|
+
* ignores the disposition, and a scriptable document when it is a page of its own.
|
|
202
|
+
*/
|
|
203
|
+
function isActiveContentType(type) {
|
|
204
|
+
return type === "text/html" || type.endsWith("/xml") || type.endsWith("+xml");
|
|
205
|
+
}
|
|
206
|
+
/**
|
|
207
|
+
* The kind a file is previewed as, read off the same content type it is stored
|
|
208
|
+
* and served with, so a file the admin shows as a video is one a browser is
|
|
209
|
+
* told is a video.
|
|
210
|
+
*/
|
|
211
|
+
function mediaKind(path) {
|
|
212
|
+
const [type] = mediaContentType(path).split("/");
|
|
213
|
+
return type === "image" || type === "video" || type === "audio" ? type : "file";
|
|
214
|
+
}
|
|
215
|
+
/**
|
|
216
|
+
* The type the CMS serves a library file as from its own origin. Only what the
|
|
217
|
+
* admin previews keeps its type, everything else goes out as opaque bytes, which
|
|
218
|
+
* `nosniff` keeps a page from loading as a script or stylesheet.
|
|
219
|
+
*/
|
|
220
|
+
function servedContentType(path) {
|
|
221
|
+
return mediaKind(path) === "file" ? "application/octet-stream" : mediaContentType(path);
|
|
222
|
+
}
|
|
223
|
+
export { joinUrl as C, conformTrailingSlash as S, withoutTrailingSlash as T, remoteMediaUrl as _, assertWithinSizeLimit as a, servedContentType as b, isActiveContentType as c, mediaContentType as d, mediaLibraries as f, parseMediaLibrary as g, megabytes as h, S3_SESSION_TOKEN_ENV as i, isLibraryFile as l, mediaPath as m, S3_ACCESS_KEY_ID_ENV as n, describeMediaRef as o, mediaLibrary as p, S3_SECRET_ACCESS_KEY_ENV as r, encodeKeyPath as s, MAX_SERVER_UPLOAD_BYTES as t, libraryDirectories as u, repoOnlyRefusal as v, trimSlashes as w, assetKey as x, s3BaseUrl as y };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { join, relative } from "pathe";
|
|
2
|
+
// src/shared/paths.ts
|
|
3
|
+
/**
|
|
4
|
+
* Path shapes both sides of the CMS have to agree on: the storage backends build
|
|
5
|
+
* them, the admin reads them back off a changeset.
|
|
6
|
+
*/
|
|
7
|
+
/** The project-relative path joining `parts`, the project root spelled `""` rather than `"."`. */
|
|
8
|
+
function projectPath(...parts) {
|
|
9
|
+
const path = join(...parts);
|
|
10
|
+
return path === "." ? "" : path;
|
|
11
|
+
}
|
|
12
|
+
/** The library-relative form of a repository path, or null when it is outside the library. */
|
|
13
|
+
function stripMediaPrefix(path, mediaDirectory) {
|
|
14
|
+
const rel = relative(mediaDirectory, path);
|
|
15
|
+
return rel.startsWith("..") ? null : rel;
|
|
16
|
+
}
|
|
17
|
+
export { stripMediaPrefix as n, projectPath as t };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { resolve } from "pathe";
|
|
2
|
+
// src/server/storage/paths.ts
|
|
3
|
+
/** Whether `filePath` is `baseDir` itself or lives under it. */
|
|
4
|
+
function isWithin(filePath, baseDir) {
|
|
5
|
+
const resolved = resolve(filePath);
|
|
6
|
+
const resolvedBase = resolve(baseDir);
|
|
7
|
+
return resolved === resolvedBase || resolved.startsWith(resolvedBase + "/");
|
|
8
|
+
}
|
|
9
|
+
/** Guards every filesystem path the CMS builds from request or git output. */
|
|
10
|
+
function assertWithinBase(filePath, baseDir) {
|
|
11
|
+
if (!isWithin(filePath, baseDir)) throw new Error("Path escapes the allowed directory");
|
|
12
|
+
}
|
|
13
|
+
export { isWithin as n, assertWithinBase as t };
|