decode location header

This commit is contained in:
Mads Rasmussen
2024-01-09 20:24:41 +01:00
parent 8f6016d538
commit d2715ffcf7
3 changed files with 15 additions and 20 deletions

View File

@@ -45,23 +45,20 @@ export class UmbPartialViewDetailServerDataSource implements UmbDetailDataSource
content: partialView.content,
};
const { error } = await tryExecuteAndNotify(
const { data, error } = await tryExecuteAndNotify(
this.#host,
PartialViewResource.postPartialView({
requestBody,
}),
);
if (error) {
return { error };
if (data) {
const newPath = decodeURIComponent(data);
const newPathUnique = this.#serverPathUniqueSerializer.toUnique(newPath);
return this.read(newPathUnique);
}
// We have to fetch the data again. The server can have modified the data after creation
// TODO: revisit when location header is added
const createdPartialViewPath = parentPath ? parentPath + '/' + requestBody.name : requestBody.name;
const createdPartialViewUnique = this.#serverPathUniqueSerializer.toUnique(createdPartialViewPath);
return this.read(createdPartialViewUnique);
return { error };
}
async read(unique: string) {

View File

@@ -53,8 +53,9 @@ export class UmbScriptDetailServerDataSource implements UmbDetailDataSource<UmbS
);
if (data) {
const createdScriptUnique = this.#serverPathUniqueSerializer.toUnique(data);
return this.read(createdScriptUnique);
const newPath = decodeURIComponent(data);
const newPathUnique = this.#serverPathUniqueSerializer.toUnique(newPath);
return this.read(newPathUnique);
}
return { error };

View File

@@ -45,23 +45,20 @@ export class UmbStylesheetDetailServerDataSource implements UmbDetailDataSource<
content: stylesheet.content,
};
const { error } = await tryExecuteAndNotify(
const { data, error } = await tryExecuteAndNotify(
this.#host,
StylesheetResource.postStylesheet({
requestBody,
}),
);
if (error) {
return { error };
if (data) {
const newPath = decodeURIComponent(data);
const newPathUnique = this.#serverPathUniqueSerializer.toUnique(newPath);
return this.read(newPathUnique);
}
// We have to fetch the data again. The server can have modified the data after creation
// TODO: revisit when location header is added
const createdStylesheetPath = parentPath ? parentPath + '/' + requestBody.name : requestBody.name;
const createdStylesheetUnique = this.#serverPathUniqueSerializer.toUnique(createdStylesheetPath);
return this.read(createdStylesheetUnique);
return { error };
}
async read(unique: string) {