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) {
|
async function uploadCoverImage(file) {
|
||||||
try {
|
try {
|
||||||
const formData = new FormData();
|
const response = await fetch(`https://worker.uploads.monochrome.qzz.io/${file.name}`, {
|
||||||
formData.append('file', file);
|
method: 'PUT',
|
||||||
|
headers: {
|
||||||
const response = await fetch('/upload', {
|
'x-api-key': 'if_youre_reading_this_fuck_off',
|
||||||
method: 'POST',
|
'Content-Type': file.type || 'application/octet-stream',
|
||||||
body: formData,
|
},
|
||||||
|
body: file,
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
const error = await response.json();
|
if (response.status === 413) throw new Error('File exceeds 10MB');
|
||||||
throw new Error(error.error || `Upload failed: ${response.status}`);
|
throw new Error(`Upload failed: ${response.status}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
const data = await response.json();
|
return `https://images.monochrome.qzz.io/${await response.text()}`;
|
||||||
return data.url;
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Cover upload error:', error);
|
console.error('Cover upload error:', error);
|
||||||
throw error;
|
throw error;
|
||||||
|
|
|
||||||
|
|
@ -37,15 +37,22 @@ let currentFavoriteAlbums = [];
|
||||||
const api = new MusicAPI(apiSettings);
|
const api = new MusicAPI(apiSettings);
|
||||||
|
|
||||||
async function uploadImage(file) {
|
async function uploadImage(file) {
|
||||||
const formData = new FormData();
|
|
||||||
formData.append('file', file);
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const response = await fetch('/upload', { method: 'POST', body: formData });
|
const response = await fetch(`https://worker.uploads.monochrome.qzz.io/${file.name}`, {
|
||||||
if (!response.ok) throw new Error(`Upload failed: ${response.status}`);
|
method: 'PUT',
|
||||||
const data = await response.json();
|
headers: {
|
||||||
if (!data.success) throw new Error(data.error || 'Upload failed');
|
'x-api-key': 'if_youre_reading_this_fuck_off',
|
||||||
return data.url;
|
'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) {
|
} catch (error) {
|
||||||
console.error('Upload error:', error);
|
console.error('Upload error:', error);
|
||||||
throw error;
|
throw error;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue