Compare commits
No commits in common. "a213d11b2b6f4c0b207146a7d02156b262d615de" and "808ae19772ff405a3b5cb52e39d5398fd81168d4" have entirely different histories.
a213d11b2b
...
808ae19772
1 changed files with 1 additions and 29 deletions
|
|
@ -20,33 +20,6 @@ const THUMBNAIL_ROLES = ['curiosity', 'emotion', 'technical'];
|
|||
// Same slug contract as the server: no separators, no traversal segments.
|
||||
const SLUG_RE = /^[A-Za-z0-9][A-Za-z0-9_-]*$/;
|
||||
|
||||
// A single exported profile file may omit `slug` (the old channels/*.json used
|
||||
// the file name as the id). Derive one so selecting such a file just works:
|
||||
// the file name wins, then the profile's own name. Bundle/list entries derive
|
||||
// from their own name only — a shared file name would collide.
|
||||
const slugify = (value) => String(value ?? '')
|
||||
.normalize('NFKD')
|
||||
.replace(/[\u0300-\u036f]/g, '')
|
||||
.trim()
|
||||
.toLowerCase()
|
||||
.replace(/[^a-z0-9_-]+/g, '-')
|
||||
.replace(/^[-_]+|[-_]+$/g, '');
|
||||
|
||||
const deriveSlug = (item, fallback) => {
|
||||
if (!item || typeof item !== 'object' || Array.isArray(item) || item.slug) return item;
|
||||
const candidate = slugify(fallback) || slugify(item.name);
|
||||
return SLUG_RE.test(candidate) ? { ...item, slug: candidate } : item;
|
||||
};
|
||||
|
||||
const withImportedSlugs = (parsed, filename) => {
|
||||
if (Array.isArray(parsed)) return parsed.map((item) => deriveSlug(item, ''));
|
||||
if (parsed && typeof parsed === 'object' && Array.isArray(parsed.profiles)) {
|
||||
return { ...parsed, profiles: parsed.profiles.map((item) => deriveSlug(item, '')) };
|
||||
}
|
||||
const stem = String(filename || '').replace(/\.[^.]+$/, '');
|
||||
return deriveSlug(parsed, stem);
|
||||
};
|
||||
|
||||
// A fresh profile. A function, not a constant, so nested arrays are never
|
||||
// shared between two opens of the form.
|
||||
const emptyForm = () => ({
|
||||
|
|
@ -530,7 +503,7 @@ export default function ChannelProfiles() {
|
|||
const data = await apiJson('/api/channels/import', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify(withImportedSlugs(parsed, file.name)),
|
||||
body: JSON.stringify(parsed),
|
||||
});
|
||||
setImportResult({
|
||||
imported: data?.imported ?? 0,
|
||||
|
|
@ -1042,7 +1015,6 @@ export default function ChannelProfiles() {
|
|||
)}
|
||||
<p className="text-xs text-muted mt-3 leading-relaxed">
|
||||
Import accepts an export bundle, a list of profiles, or a single profile.
|
||||
A single file may omit its slug — it is derived from the file name.
|
||||
</p>
|
||||
</div>
|
||||
</aside>
|
||||
|
|
|
|||
Loading…
Reference in a new issue