client/posts: make discard thumbnail link delete existing custom thumb

I can see the intent, sadly this was always broken in the case where the
post already has a custom thumbnail from initial load, and we don't drag
any new files. It did not actually remove the existing thumbnail.
Before 12c4542bb2482fac89aae9a04b15984a56bb8fb0 it would actually crash,
but this now makes it behave as expected.
Also properly syncs internal state with what's displayed to the user.
This commit is contained in:
Eva
2024-03-28 03:39:33 +01:00
parent 061c604f14
commit 795ba068e6
3 changed files with 24 additions and 15 deletions

View File

@ -294,11 +294,16 @@ class Api extends events.EventTarget {
// transform the request: upload each file, then make the request use
// its tokens.
data = Object.assign({}, data);
let fileData = {};
let abortFunction = () => {};
let promise = Promise.resolve();
if (files) {
for (let key of Object.keys(files)) {
const file = files[key];
if (file === null) {
fileData[key] = null;
continue;
}
const fileId = this._getFileId(file);
if (fileTokens[fileId]) {
data[key + "Token"] = fileTokens[fileId];
@ -324,7 +329,7 @@ class Api extends events.EventTarget {
url,
requestFactory,
data,
{},
fileData,
options
);
abortFunction = () => requestPromise.abort();
@ -388,7 +393,7 @@ class Api extends events.EventTarget {
if (files) {
for (let key of Object.keys(files)) {
const value = files[key];
if (value.constructor === String) {
if (value !== null && value.constructor === String) {
data[key + "Url"] = value;
} else {
req.attach(key, value || new Blob());