filetransfer: use enabeld in settings and profile.

This commit is contained in:
Miroslav Šedivý 2024-06-16 17:27:26 +02:00
parent 4bd6eb6db9
commit ad101ddb0d
2 changed files with 27 additions and 18 deletions

View File

@ -2,11 +2,11 @@
<div style="width: 100%"> <div style="width: 100%">
<div class="files" v-if="tab === 'filetransfer'"> <div class="files" v-if="tab === 'filetransfer'">
<div class="files-cwd"> <div class="files-cwd">
<p>Filetransfer is {{ isLocked ? 'locked' : 'unlocked' }} for users</p> <p>Filetransfer is {{ enabledInSettings ? 'unlocked' : 'locked' }} for users</p>
<i :class="['fas', isLocked ? 'fa-lock' : 'fa-unlock', 'refresh']" @click="setLock(!isLocked)" :title="isLocked ? 'Unlock' : 'Lock'" /> <i v-if="props.neko.is_admin" :class="['fas', enabledInSettings ? 'fa-unlock' : 'fa-lock', 'refresh']" @click="toggleEnabled(!enabledInSettings)" :title="enabledInSettings ? 'Lock' : 'Unlock'" />
</div> </div>
<div class="files-cwd"> <div class="files-cwd">
<p>{{ enabled ? cwd : 'Filetransfer is disabled' }}</p> <p>{{ enabledSystemWide ? cwd : 'Filetransfer is disabled system wide' }}</p>
<i class="fas fa-rotate-right refresh" @click="refresh" /> <i class="fas fa-rotate-right refresh" @click="refresh" />
</div> </div>
<div class="files-list"> <div class="files-list">
@ -14,10 +14,10 @@
<i :class="fileIcon(item)" /> <i :class="fileIcon(item)" />
<p class="file-name" :title="item.name">{{ item.name }}</p> <p class="file-name" :title="item.name">{{ item.name }}</p>
<p class="file-size">{{ fileSize(item.size) }}</p> <p class="file-size">{{ fileSize(item.size) }}</p>
<i v-if="item.type !== 'dir' && enabledForMe" class="fas fa-download download" @click="download(item)" /> <i v-if="item.type !== 'dir' && enabled" class="fas fa-download download" @click="download(item)" />
</div> </div>
</div> </div>
<div class="transfer-area" v-if="enabledForMe"> <div class="transfer-area" v-if="enabled">
<div class="transfers" v-if="transfers.length > 0"> <div class="transfers" v-if="transfers.length > 0">
<p v-if="downloads.length > 0" class="transfers-list-header"> <p v-if="downloads.length > 0" class="transfers-list-header">
<span> Downloads </span> <span> Downloads </span>
@ -286,8 +286,15 @@ const props = defineProps<{
const api = props.neko.withApi(FiletransferApi) as FiletransferApi const api = props.neko.withApi(FiletransferApi) as FiletransferApi
const enabled = ref(false) // config option to enable/disable filetransfer plugin
const enabledForMe = computed(() => enabled.value && (props.neko.is_admin || (!props.neko.is_admin && !isLocked.value))) const enabledSystemWide = ref(false)
// dynamic settings for filetransfer plugin
const enabledInSettings = computed(() => !(props.neko.state.settings?.plugins?.filetransfer?.enabled === false))
// user specific setting to enable/disable filetransfer plugin
const enabledForMe = computed(() => !(props.neko.session?.profile?.plugins?.filetransfer?.enabled === false))
// combined enabled state for filetransfer plugin and user
const enabled = computed(() => enabledSystemWide.value && (enabledInSettings.value || props.neko.is_admin) && enabledForMe.value)
const cwd = ref('') const cwd = ref('')
const files = ref<Item[]>([]) const files = ref<Item[]>([])
const transfers = reactive<FileTransfer[]>([]) const transfers = reactive<FileTransfer[]>([])
@ -301,7 +308,7 @@ onMounted(async () => {
switch (event) { switch (event) {
case FILETRANSFER_UPDATE: case FILETRANSFER_UPDATE:
const msg = payload as Message const msg = payload as Message
enabled.value = msg.enabled enabledSystemWide.value = msg.enabled
cwd.value = msg.root_dir cwd.value = msg.root_dir
files.value = msg.files files.value = msg.files
break break
@ -309,6 +316,14 @@ onMounted(async () => {
}) })
}) })
async function toggleEnabled(inEnabled = true) {
try {
await props.neko.room.settingsSet({ plugins: { filetransfer: { "enabled": inEnabled} } })
} catch (e: any) {
alert(e.response ? e.response.data.message : e)
}
}
function refresh() { function refresh() {
props.neko.sendMessage(FILETRANSFER_UPDATE) props.neko.sendMessage(FILETRANSFER_UPDATE)
} }
@ -523,14 +538,4 @@ function fileSize(size: number) {
} }
return Math.round(size / (1024 * 1024 * 1024 * 1024)) + ' TB' return Math.round(size / (1024 * 1024 * 1024 * 1024)) + ' TB'
} }
const isLocked = computed(() => props.neko.state.settings?.plugins?.filetransfer === true)
async function setLock(isLocked = true) {
try {
await props.neko.room.settingsSet({ plugins: { filetransfer: isLocked } })
} catch (e: any) {
alert(e.response ? e.response.data.message : e)
}
}
</script> </script>

View File

@ -1,3 +1,7 @@
export interface Settings {
enabled: boolean
}
export const FILETRANSFER_UPDATE = "filetransfer/update" export const FILETRANSFER_UPDATE = "filetransfer/update"
export interface Message { export interface Message {