hippofish/packages/frontend/src/pages/settings/drive.vue

155 lines
4.2 KiB
Vue
Raw Normal View History

<template>
2023-01-06 05:40:17 +01:00
<div class="_gaps_m">
2023-01-05 13:04:56 +01:00
<FormSection v-if="!fetching" first>
<template #label>{{ i18n.ts.usageAmount }}</template>
2023-01-05 13:04:56 +01:00
2023-01-06 05:40:17 +01:00
<div class="_gaps_m">
2023-05-30 03:20:06 +02:00
<div>
<div :class="$style.meter"><div :class="$style.meterValue" :style="meterStyle"></div></div>
2023-01-05 13:04:56 +01:00
</div>
<FormSplit>
<MkKeyValue>
<template #key>{{ i18n.ts.capacity }}</template>
<template #value>{{ bytes(capacity, 1) }}</template>
</MkKeyValue>
<MkKeyValue>
<template #key>{{ i18n.ts.inUse }}</template>
<template #value>{{ bytes(usage, 1) }}</template>
</MkKeyValue>
</FormSplit>
2021-01-23 10:14:57 +01:00
</div>
2021-11-28 12:07:37 +01:00
</FormSection>
<FormSection>
<template #label>{{ i18n.ts.statistics }}</template>
2023-05-19 13:52:15 +02:00
<MkChart src="per-user-drive" :args="{ user: $i }" span="day" :limit="7 * 5" :bar="true" :stacked="true" :detailed="false" :aspectRatio="6"/>
2021-11-28 12:07:37 +01:00
</FormSection>
<FormSection>
2023-01-06 05:40:17 +01:00
<div class="_gaps_m">
2023-01-05 13:04:56 +01:00
<FormLink @click="chooseUploadFolder()">
{{ i18n.ts.uploadFolder }}
<template #suffix>{{ uploadFolder ? uploadFolder.name : '-' }}</template>
2023-02-14 05:17:00 +01:00
<template #suffixIcon><i class="ti ti-folder"></i></template>
2023-01-05 13:04:56 +01:00
</FormLink>
<FormLink to="/settings/drive/cleaner">
{{ i18n.ts.drivecleaner }}
</FormLink>
2023-01-07 06:59:54 +01:00
<MkSwitch v-model="keepOriginalUploading">
2023-01-05 13:04:56 +01:00
<template #label>{{ i18n.ts.keepOriginalUploading }}</template>
<template #caption>{{ i18n.ts.keepOriginalUploadingDescription }}</template>
2023-01-07 06:59:54 +01:00
</MkSwitch>
2023-05-19 13:52:15 +02:00
<MkSwitch v-model="alwaysMarkNsfw" @update:modelValue="saveProfile()">
2023-01-05 13:04:56 +01:00
<template #label>{{ i18n.ts.alwaysMarkSensitive }}</template>
2023-01-07 06:59:54 +01:00
</MkSwitch>
2023-05-19 13:52:15 +02:00
<MkSwitch v-model="autoSensitive" @update:modelValue="saveProfile()">
2023-01-05 13:04:56 +01:00
<template #label>{{ i18n.ts.enableAutoSensitive }}<span class="_beta">{{ i18n.ts.beta }}</span></template>
<template #caption>{{ i18n.ts.enableAutoSensitiveDescription }}</template>
2023-01-07 06:59:54 +01:00
</MkSwitch>
2023-01-05 13:04:56 +01:00
</div>
2021-11-28 12:07:37 +01:00
</FormSection>
</div>
</template>
<script lang="ts" setup>
import { computed, ref } from 'vue';
2022-05-30 14:09:22 +02:00
import tinycolor from 'tinycolor2';
2021-11-28 12:07:37 +01:00
import FormLink from '@/components/form/link.vue';
2023-01-07 06:59:54 +01:00
import MkSwitch from '@/components/MkSwitch.vue';
2021-11-28 12:07:37 +01:00
import FormSection from '@/components/form/section.vue';
import MkKeyValue from '@/components/MkKeyValue.vue';
2021-12-30 13:47:48 +01:00
import FormSplit from '@/components/form/split.vue';
2021-11-11 18:02:25 +01:00
import * as os from '@/os';
import bytes from '@/filters/bytes';
import { defaultStore } from '@/store';
import MkChart from '@/components/MkChart.vue';
import { i18n } from '@/i18n';
import { definePageMetadata } from '@/scripts/page-metadata';
import { $i } from '@/account';
const fetching = ref(true);
const usage = ref<any>(null);
const capacity = ref<any>(null);
const uploadFolder = ref<any>(null);
let alwaysMarkNsfw = $ref($i.alwaysMarkNsfw);
let autoSensitive = $ref($i.autoSensitive);
const meterStyle = computed(() => {
return {
width: `${usage.value / capacity.value * 100}%`,
background: tinycolor({
h: 180 - (usage.value / capacity.value * 180),
s: 0.7,
l: 0.5,
}),
};
});
2021-10-24 05:32:41 +02:00
const keepOriginalUploading = computed(defaultStore.makeGetterSetter('keepOriginalUploading'));
2021-01-23 10:14:57 +01:00
os.api('drive').then(info => {
capacity.value = info.capacity;
usage.value = info.usage;
fetching.value = false;
});
2021-01-23 10:14:57 +01:00
if (defaultStore.state.uploadFolder) {
os.api('drive/folders/show', {
folderId: defaultStore.state.uploadFolder,
}).then(response => {
uploadFolder.value = response;
});
}
2021-01-23 10:14:57 +01:00
function chooseUploadFolder() {
os.selectDriveFolder(false).then(async folder => {
defaultStore.set('uploadFolder', folder ? folder.id : null);
os.success();
if (defaultStore.state.uploadFolder) {
uploadFolder.value = await os.api('drive/folders/show', {
folderId: defaultStore.state.uploadFolder,
});
} else {
uploadFolder.value = null;
}
});
}
2021-01-23 10:14:57 +01:00
function saveProfile() {
os.api('i/update', {
alwaysMarkNsfw: !!alwaysMarkNsfw,
autoSensitive: !!autoSensitive,
}).catch(err => {
os.alert({
type: 'error',
title: i18n.ts.error,
text: err.message,
});
alwaysMarkNsfw = true;
});
}
const headerActions = $computed(() => []);
const headerTabs = $computed(() => []);
definePageMetadata({
title: i18n.ts.drive,
icon: 'ti ti-cloud',
});
</script>
2023-05-30 03:20:06 +02:00
<style lang="scss" module>
.meter {
2023-05-30 07:38:13 +02:00
height: 10px;
2023-05-30 03:20:06 +02:00
background: rgba(0, 0, 0, 0.1);
border-radius: 999px;
overflow: clip;
}
2023-05-30 03:20:06 +02:00
.meterValue {
height: 100%;
border-radius: 999px;
}
</style>