fix image uploads
This commit is contained in:
parent
1ba27308d1
commit
992974d790
2 changed files with 25 additions and 18 deletions
20
js/app.js
20
js/app.js
|
|
@ -357,21 +357,21 @@ async function disablePwaForAuthGate() {
|
|||
|
||||
async function uploadCoverImage(file) {
|
||||
try {
|
||||
const formData = new FormData();
|
||||
formData.append('file', file);
|
||||
|
||||
const response = await fetch('/upload', {
|
||||
method: 'POST',
|
||||
body: formData,
|
||||
const response = await fetch(`https://worker.uploads.monochrome.qzz.io/${file.name}`, {
|
||||
method: 'PUT',
|
||||
headers: {
|
||||
'x-api-key': 'if_youre_reading_this_fuck_off',
|
||||
'Content-Type': file.type || 'application/octet-stream',
|
||||
},
|
||||
body: file,
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
const error = await response.json();
|
||||
throw new Error(error.error || `Upload failed: ${response.status}`);
|
||||
if (response.status === 413) throw new Error('File exceeds 10MB');
|
||||
throw new Error(`Upload failed: ${response.status}`);
|
||||
}
|
||||
|
||||
const data = await response.json();
|
||||
return data.url;
|
||||
return `https://images.monochrome.qzz.io/${await response.text()}`;
|
||||
} catch (error) {
|
||||
console.error('Cover upload error:', error);
|
||||
throw error;
|
||||
|
|
|
|||
|
|
@ -37,15 +37,22 @@ let currentFavoriteAlbums = [];
|
|||
const api = new MusicAPI(apiSettings);
|
||||
|
||||
async function uploadImage(file) {
|
||||
const formData = new FormData();
|
||||
formData.append('file', file);
|
||||
|
||||
try {
|
||||
const response = await fetch('/upload', { method: 'POST', body: formData });
|
||||
if (!response.ok) throw new Error(`Upload failed: ${response.status}`);
|
||||
const data = await response.json();
|
||||
if (!data.success) throw new Error(data.error || 'Upload failed');
|
||||
return data.url;
|
||||
const response = await fetch(`https://worker.uploads.monochrome.qzz.io/${file.name}`, {
|
||||
method: 'PUT',
|
||||
headers: {
|
||||
'x-api-key': 'if_youre_reading_this_fuck_off',
|
||||
'Content-Type': file.type || 'application/octet-stream',
|
||||
},
|
||||
body: file,
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
if (response.status === 413) throw new Error('File exceeds 10MB');
|
||||
throw new Error(`Upload failed: ${response.status}`);
|
||||
}
|
||||
|
||||
return `https://images.monochrome.qzz.io/${await response.text()}`;
|
||||
} catch (error) {
|
||||
console.error('Upload error:', error);
|
||||
throw error;
|
||||
|
|
|
|||
Loading…
Reference in a new issue