From 10c436b24aa9e1598f1e5a227ef783956c23076e Mon Sep 17 00:00:00 2001 From: eugenijm Date: Fri, 21 Feb 2020 01:05:59 +0300 Subject: [PATCH] Added the ability to upload image as a setting value --- CHANGELOG.md | 1 + src/api/mediaUpload.js | 19 ++ src/lang/en.js | 5 +- src/views/settings/components/Inputs.vue | 15 +- .../inputComponents/ImageUploadInput.vue | 204 ++++++++++++++++++ .../components/inputComponents/index.js | 1 + 6 files changed, 243 insertions(+), 2 deletions(-) create mode 100644 src/api/mediaUpload.js create mode 100644 src/views/settings/components/inputComponents/ImageUploadInput.vue diff --git a/CHANGELOG.md b/CHANGELOG.md index 0f51d123..dfa4826a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -22,6 +22,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). ### Added - Link settings that enable registrations and invites +- Ability to upload logo, background, default user avatar, instance thumbnail, and NSFW hiding images ### Changed diff --git a/src/api/mediaUpload.js b/src/api/mediaUpload.js new file mode 100644 index 00000000..1cbde204 --- /dev/null +++ b/src/api/mediaUpload.js @@ -0,0 +1,19 @@ +import { getToken } from '@/utils/auth' +import { baseName } from './utils' + +const UPLOAD_URL = '/api/v1/media' + +export function uploadMedia({ formData, authHost }) { + const url = baseName(authHost) + UPLOAD_URL + + return fetch(url, { + body: formData, + method: 'POST', + headers: authHeaders() + }) + .then((data) => data.json()) +} + +const authHeaders = () => { + return { 'Authorization': `Bearer ${getToken()}` } +} diff --git a/src/lang/en.js b/src/lang/en.js index 2e504315..a6f65378 100644 --- a/src/lang/en.js +++ b/src/lang/en.js @@ -388,7 +388,10 @@ export default { instanceReboot: 'Reboot Instance', restartApp: 'You must restart the instance to apply settings', restartSuccess: 'Instance rebooted successfully!', - removeSettingConfirmation: 'Are you sure you want to remove this setting\'s value from the database?' + removeSettingConfirmation: 'Are you sure you want to remove this setting\'s value from the database?', + changeImage: 'Change image', + uploadImage: 'Upload image', + remove: 'Remove' }, invites: { inviteTokens: 'Invite tokens', diff --git a/src/views/settings/components/Inputs.vue b/src/views/settings/components/Inputs.vue index 3214485f..a30e8e19 100644 --- a/src/views/settings/components/Inputs.vue +++ b/src/views/settings/components/Inputs.vue @@ -33,8 +33,16 @@
+ +
+
+
+
+ +
+ {{ $t('settings.changeImage') }} +
+ +
+
+
+
+ + {{ $t('settings.uploadImage') }} + + + + {{ $t('settings.remove') }} + +
+
+ + + + + diff --git a/src/views/settings/components/inputComponents/index.js b/src/views/settings/components/inputComponents/index.js index 3b9bc788..11281950 100644 --- a/src/views/settings/components/inputComponents/index.js +++ b/src/views/settings/components/inputComponents/index.js @@ -2,6 +2,7 @@ export { default as AutoLinkerInput } from './AutoLinkerInput' export { default as EditableKeywordInput } from './EditableKeywordInput' export { default as CrontabInput } from './CrontabInput' export { default as IconsInput } from './IconsInput' +export { default as ImageUploadInput } from './ImageUploadInput' export { default as MascotsInput } from './MascotsInput' export { default as ProxyUrlInput } from './ProxyUrlInput' export { default as PruneInput } from './PruneInput'