encode + decode file system detail paths

This commit is contained in:
Mads Rasmussen
2024-01-09 16:21:27 +01:00
parent a0ad88015a
commit d0ef956e2e
6 changed files with 42 additions and 30 deletions

View File

@@ -12,7 +12,7 @@ export const detailHandlers = [
return res(
ctx.status(201),
ctx.set({
Location: path,
Location: encodeURIComponent(path),
}),
);
}),
@@ -20,14 +20,14 @@ export const detailHandlers = [
rest.get(umbracoPath(`${UMB_SLUG}/:path`), (req, res, ctx) => {
const path = req.params.path as string;
if (!path) return res(ctx.status(400));
const response = umbPartialViewMockDB.file.read(path);
const response = umbPartialViewMockDB.file.read(decodeURIComponent(path));
return res(ctx.status(200), ctx.json(response));
}),
rest.delete(umbracoPath(`${UMB_SLUG}/:path`), (req, res, ctx) => {
const path = req.params.path as string;
if (!path) return res(ctx.status(400));
umbPartialViewMockDB.file.delete(path);
umbPartialViewMockDB.file.delete(decodeURIComponent(path));
return res(ctx.status(200));
}),
@@ -36,7 +36,7 @@ export const detailHandlers = [
if (!path) return res(ctx.status(400));
const requestBody = (await req.json()) as UpdateStylesheetRequestModel;
if (!requestBody) return res(ctx.status(400, 'no body found'));
umbPartialViewMockDB.file.update(path, requestBody);
umbPartialViewMockDB.file.update(decodeURIComponent(path), requestBody);
return res(ctx.status(200));
}),
];

View File

@@ -12,7 +12,7 @@ export const detailHandlers = [
return res(
ctx.status(201),
ctx.set({
Location: path,
Location: encodeURIComponent(path),
}),
);
}),
@@ -20,14 +20,14 @@ export const detailHandlers = [
rest.get(umbracoPath(`${UMB_SLUG}/:path`), (req, res, ctx) => {
const path = req.params.path as string;
if (!path) return res(ctx.status(400));
const response = umbScriptMockDb.file.read(path);
const response = umbScriptMockDb.file.read(decodeURIComponent(path));
return res(ctx.status(200), ctx.json(response));
}),
rest.delete(umbracoPath(`${UMB_SLUG}/:path`), (req, res, ctx) => {
const path = req.params.path as string;
if (!path) return res(ctx.status(400));
umbScriptMockDb.file.delete(path);
umbScriptMockDb.file.delete(decodeURIComponent(path));
return res(ctx.status(200));
}),
@@ -36,7 +36,7 @@ export const detailHandlers = [
if (!path) return res(ctx.status(400));
const requestBody = (await req.json()) as UpdateStylesheetRequestModel;
if (!requestBody) return res(ctx.status(400, 'no body found'));
umbScriptMockDb.file.update(path, requestBody);
umbScriptMockDb.file.update(decodeURIComponent(path), requestBody);
return res(ctx.status(200));
}),
];

View File

@@ -12,7 +12,7 @@ export const detailHandlers = [
return res(
ctx.status(201),
ctx.set({
Location: path,
Location: encodeURIComponent(path),
}),
);
}),
@@ -20,14 +20,14 @@ export const detailHandlers = [
rest.get(umbracoPath(`${UMB_SLUG}/:path`), (req, res, ctx) => {
const path = req.params.path as string;
if (!path) return res(ctx.status(400));
const response = umbStylesheetData.file.read(path);
const response = umbStylesheetData.file.read(decodeURIComponent(path));
return res(ctx.status(200), ctx.json(response));
}),
rest.delete(umbracoPath(`${UMB_SLUG}/:path`), (req, res, ctx) => {
const path = req.params.path as string;
if (!path) return res(ctx.status(400));
umbStylesheetData.file.delete(path);
umbStylesheetData.file.delete(decodeURIComponent(path));
return res(ctx.status(200));
}),
@@ -36,7 +36,7 @@ export const detailHandlers = [
if (!path) return res(ctx.status(400));
const requestBody = (await req.json()) as UpdateStylesheetRequestModel;
if (!requestBody) return res(ctx.status(400, 'no body found'));
umbStylesheetData.file.update(path, requestBody);
umbStylesheetData.file.update(decodeURIComponent(path), requestBody);
return res(ctx.status(200));
}),
];

View File

@@ -40,9 +40,7 @@ export class UmbPartialViewDetailServerDataSource implements UmbDetailDataSource
// TODO: make data mapper to prevent errors
const requestBody: CreatePartialViewRequestModel = {
parent: {
path: parentPath,
},
parent: parentPath ? { path: parentPath } : null,
name: appendFileExtensionIfNeeded(partialView.name, '.cshtml'),
content: partialView.content,
};
@@ -70,8 +68,12 @@ export class UmbPartialViewDetailServerDataSource implements UmbDetailDataSource
if (!unique) throw new Error('Unique is missing');
const path = this.#serverPathUniqueSerializer.toServerPath(unique);
if (!path) throw new Error('Path is missing');
const { data, error } = await tryExecuteAndNotify(this.#host, PartialViewResource.getPartialViewByPath({ path }));
const { data, error } = await tryExecuteAndNotify(
this.#host,
PartialViewResource.getPartialViewByPath({ path: encodeURIComponent(path) }),
);
if (error || !data) {
return { error };
@@ -93,6 +95,7 @@ export class UmbPartialViewDetailServerDataSource implements UmbDetailDataSource
if (!data.unique) throw new Error('Unique is missing');
const path = this.#serverPathUniqueSerializer.toServerPath(data.unique);
if (!path) throw new Error('Path is missing');
const requestBody: UpdatePartialViewRequestModel = {
content: data.content,
@@ -101,7 +104,7 @@ export class UmbPartialViewDetailServerDataSource implements UmbDetailDataSource
const { error } = await tryExecuteAndNotify(
this.#host,
PartialViewResource.putPartialViewByPath({
path,
path: encodeURIComponent(path),
requestBody,
}),
);
@@ -117,11 +120,12 @@ export class UmbPartialViewDetailServerDataSource implements UmbDetailDataSource
if (!unique) throw new Error('Unique is missing');
const path = this.#serverPathUniqueSerializer.toServerPath(unique);
if (!path) throw new Error('Path is missing');
return tryExecuteAndNotify(
this.#host,
PartialViewResource.deletePartialViewByPath({
path,
path: encodeURIComponent(path),
}),
);
}

View File

@@ -40,9 +40,7 @@ export class UmbScriptDetailServerDataSource implements UmbDetailDataSource<UmbS
// TODO: make data mapper to prevent errors
const requestBody: CreateScriptRequestModel = {
parent: {
path: parentPath,
},
parent: parentPath ? { path: parentPath } : null,
name: appendFileExtensionIfNeeded(script.name, '.js'),
content: script.content,
};
@@ -66,8 +64,12 @@ export class UmbScriptDetailServerDataSource implements UmbDetailDataSource<UmbS
if (!unique) throw new Error('Unique is missing');
const path = this.#serverPathUniqueSerializer.toServerPath(unique);
if (!path) throw new Error('Path is missing');
const { data, error } = await tryExecuteAndNotify(this.#host, ScriptResource.getScriptByPath({ path }));
const { data, error } = await tryExecuteAndNotify(
this.#host,
ScriptResource.getScriptByPath({ path: encodeURIComponent(path) }),
);
if (error || !data) {
return { error };
@@ -89,6 +91,7 @@ export class UmbScriptDetailServerDataSource implements UmbDetailDataSource<UmbS
if (!data.unique) throw new Error('Unique is missing');
const path = this.#serverPathUniqueSerializer.toServerPath(data.unique);
if (!path) throw new Error('Path is missing');
const requestBody: UpdateScriptRequestModel = {
content: data.content,
@@ -97,7 +100,7 @@ export class UmbScriptDetailServerDataSource implements UmbDetailDataSource<UmbS
const { error } = await tryExecuteAndNotify(
this.#host,
ScriptResource.putScriptByPath({
path,
path: encodeURIComponent(path),
requestBody,
}),
);
@@ -113,11 +116,12 @@ export class UmbScriptDetailServerDataSource implements UmbDetailDataSource<UmbS
if (!unique) throw new Error('Unique is missing');
const path = this.#serverPathUniqueSerializer.toServerPath(unique);
if (!path) throw new Error('Path is missing');
return tryExecuteAndNotify(
this.#host,
ScriptResource.deleteScriptByPath({
path,
path: encodeURIComponent(path),
}),
);
}

View File

@@ -40,9 +40,7 @@ export class UmbStylesheetDetailServerDataSource implements UmbDetailDataSource<
// TODO: make data mapper to prevent errors
const requestBody: CreateStylesheetRequestModel = {
parent: {
path: parentPath,
},
parent: parentPath ? { path: parentPath } : null,
name: appendFileExtensionIfNeeded(stylesheet.name, '.css'),
content: stylesheet.content,
};
@@ -70,8 +68,12 @@ export class UmbStylesheetDetailServerDataSource implements UmbDetailDataSource<
if (!unique) throw new Error('Unique is missing');
const path = this.#serverPathUniqueSerializer.toServerPath(unique);
if (!path) throw new Error('Path is missing');
const { data, error } = await tryExecuteAndNotify(this.#host, StylesheetResource.getStylesheetByPath({ path }));
const { data, error } = await tryExecuteAndNotify(
this.#host,
StylesheetResource.getStylesheetByPath({ path: encodeURIComponent(path) }),
);
if (error || !data) {
return { error };
@@ -93,6 +95,7 @@ export class UmbStylesheetDetailServerDataSource implements UmbDetailDataSource<
if (!data.unique) throw new Error('Unique is missing');
const path = this.#serverPathUniqueSerializer.toServerPath(data.unique);
if (!path) throw new Error('Path is missing');
const requestBody: UpdateStylesheetRequestModel = {
content: data.content,
@@ -101,7 +104,7 @@ export class UmbStylesheetDetailServerDataSource implements UmbDetailDataSource<
const { error } = await tryExecuteAndNotify(
this.#host,
StylesheetResource.putStylesheetByPath({
path,
path: encodeURIComponent(path),
requestBody,
}),
);
@@ -117,11 +120,12 @@ export class UmbStylesheetDetailServerDataSource implements UmbDetailDataSource<
if (!unique) throw new Error('Unique is missing');
const path = this.#serverPathUniqueSerializer.toServerPath(unique);
if (!path) throw new Error('Path is missing');
return tryExecuteAndNotify(
this.#host,
StylesheetResource.deleteStylesheetByPath({
path,
path: encodeURIComponent(path),
}),
);
}