[feat] user assets (#3504)
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
window.app.component('lnbits-admin-assets-config', {
|
||||
props: ['form-data'],
|
||||
template: '#lnbits-admin-assets-config',
|
||||
mixins: [window.windowMixin],
|
||||
data() {
|
||||
return {
|
||||
newAllowedAssetMimeType: '',
|
||||
newNoLimitUser: ''
|
||||
}
|
||||
},
|
||||
async created() {},
|
||||
methods: {
|
||||
addAllowedAssetMimeType() {
|
||||
if (this.newAllowedAssetMimeType) {
|
||||
this.removeAllowedAssetMimeType(this.newAllowedAssetMimeType)
|
||||
this.formData.lnbits_assets_allowed_mime_types.push(
|
||||
this.newAllowedAssetMimeType
|
||||
)
|
||||
this.newAllowedAssetMimeType = ''
|
||||
}
|
||||
},
|
||||
removeAllowedAssetMimeType(type) {
|
||||
const index = this.formData.lnbits_assets_allowed_mime_types.indexOf(type)
|
||||
if (index !== -1) {
|
||||
this.formData.lnbits_assets_allowed_mime_types.splice(index, 1)
|
||||
}
|
||||
},
|
||||
addNewNoLimitUser() {
|
||||
if (this.newNoLimitUser) {
|
||||
this.removeNoLimitUser(this.newNoLimitUser)
|
||||
this.formData.lnbits_assets_no_limit_users.push(this.newNoLimitUser)
|
||||
this.newNoLimitUser = ''
|
||||
}
|
||||
},
|
||||
removeNoLimitUser(user) {
|
||||
if (user) {
|
||||
this.formData.lnbits_assets_no_limit_users =
|
||||
this.formData.lnbits_assets_no_limit_users.filter(u => u !== user)
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
@@ -1,74 +0,0 @@
|
||||
window.app.component('lnbits-admin-library', {
|
||||
props: ['form-data'],
|
||||
template: '#lnbits-admin-library',
|
||||
mixins: [window.windowMixin],
|
||||
data() {
|
||||
return {
|
||||
library_images: []
|
||||
}
|
||||
},
|
||||
async created() {
|
||||
await this.getUploadedImages()
|
||||
},
|
||||
methods: {
|
||||
onImageInput(e) {
|
||||
const file = e.target.files[0]
|
||||
if (file) {
|
||||
this.uploadImage(file)
|
||||
}
|
||||
},
|
||||
uploadImage(file) {
|
||||
const formData = new FormData()
|
||||
formData.append('file', file)
|
||||
LNbits.api
|
||||
.request(
|
||||
'POST',
|
||||
'/admin/api/v1/images',
|
||||
this.g.user.wallets[0].adminkey,
|
||||
formData,
|
||||
{headers: {'Content-Type': 'multipart/form-data'}}
|
||||
)
|
||||
.then(() => {
|
||||
this.$q.notify({
|
||||
type: 'positive',
|
||||
message: 'Image uploaded!',
|
||||
icon: null
|
||||
})
|
||||
this.getUploadedImages()
|
||||
})
|
||||
.catch(LNbits.utils.notifyApiError)
|
||||
},
|
||||
getUploadedImages() {
|
||||
LNbits.api
|
||||
.request('GET', '/admin/api/v1/images', this.g.user.wallets[0].inkey)
|
||||
.then(response => {
|
||||
this.library_images = response.data.map(image => ({
|
||||
...image,
|
||||
url: `${window.origin}/${image.directory}/${image.filename}`
|
||||
}))
|
||||
})
|
||||
.catch(LNbits.utils.notifyApiError)
|
||||
},
|
||||
deleteImage(filename) {
|
||||
LNbits.utils
|
||||
.confirmDialog('Are you sure you want to delete this image?')
|
||||
.onOk(() => {
|
||||
LNbits.api
|
||||
.request(
|
||||
'DELETE',
|
||||
`/admin/api/v1/images/${filename}`,
|
||||
this.g.user.wallets[0].adminkey
|
||||
)
|
||||
.then(() => {
|
||||
this.$q.notify({
|
||||
type: 'positive',
|
||||
message: 'Image deleted!',
|
||||
icon: null
|
||||
})
|
||||
this.getUploadedImages()
|
||||
})
|
||||
.catch(LNbits.utils.notifyApiError)
|
||||
})
|
||||
}
|
||||
}
|
||||
})
|
||||
Reference in New Issue
Block a user