summaryrefslogtreecommitdiff
path: root/packages/client/src/pages/admin/files.vue
blob: dd309180a7624c55c91e92d652899a513a67bb82 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
<template>
<div>
	<MkStickyContainer>
		<template #header><XHeader :actions="headerActions"/></template>
		<MkSpacer :content-max="900">
			<div class="xrmjdkdw">
				<div>
					<div class="inputs" style="display: flex; gap: var(--margin); flex-wrap: wrap;">
						<MkSelect v-model="origin" style="margin: 0; flex: 1;">
							<template #label>{{ $ts.instance }}</template>
							<option value="combined">{{ $ts.all }}</option>
							<option value="local">{{ $ts.local }}</option>
							<option value="remote">{{ $ts.remote }}</option>
						</MkSelect>
						<MkInput v-model="searchHost" :debounce="true" type="search" style="margin: 0; flex: 1;" :disabled="pagination.params.origin === 'local'">
							<template #label>{{ $ts.host }}</template>
						</MkInput>
					</div>
					<div class="inputs" style="display: flex; gap: var(--margin); flex-wrap: wrap; padding-top: 1.2em;">
						<MkInput v-model="userId" :debounce="true" type="search" style="margin: 0; flex: 1;">
							<template #label>User ID</template>
						</MkInput>
						<MkInput v-model="type" :debounce="true" type="search" style="margin: 0; flex: 1;">
							<template #label>MIME type</template>
						</MkInput>
					</div>
					<MkFileListForAdmin :pagination="pagination" :view-mode="viewMode"/>
				</div>
			</div>
		</MkSpacer>
	</MkStickyContainer>
</div>
</template>

<script lang="ts" setup>
import { computed, defineAsyncComponent } from 'vue';
import * as Acct from 'misskey-js/built/acct';
import XHeader from './_header_.vue';
import MkButton from '@/components/ui/button.vue';
import MkInput from '@/components/form/input.vue';
import MkSelect from '@/components/form/select.vue';
import MkFileListForAdmin from '@/components/file-list-for-admin.vue';
import bytes from '@/filters/bytes';
import * as os from '@/os';
import { i18n } from '@/i18n';
import { definePageMetadata } from '@/scripts/page-metadata';

let origin = $ref('local');
let type = $ref(null);
let searchHost = $ref('');
let userId = $ref('');
let viewMode = $ref('grid');
const pagination = {
	endpoint: 'admin/drive/files' as const,
	limit: 10,
	params: computed(() => ({
		type: (type && type !== '') ? type : null,
		userId: (userId && userId !== '') ? userId : null,
		origin: origin,
		hostname: (searchHost && searchHost !== '') ? searchHost : null,
	})),
};

function clear() {
	os.confirm({
		type: 'warning',
		text: i18n.ts.clearCachedFilesConfirm,
	}).then(({ canceled }) => {
		if (canceled) return;

		os.apiWithDialog('admin/drive/clean-remote-files', {});
	});
}

function show(file) {
	os.pageWindow(`/admin/file/${file.id}`);
}

async function find() {
	const { canceled, result: q } = await os.inputText({
		title: i18n.ts.fileIdOrUrl,
		allowEmpty: false,
	});
	if (canceled) return;

	os.api('admin/drive/show-file', q.startsWith('http://') || q.startsWith('https://') ? { url: q.trim() } : { fileId: q.trim() }).then(file => {
		show(file);
	}).catch(err => {
		if (err.code === 'NO_SUCH_FILE') {
			os.alert({
				type: 'error',
				text: i18n.ts.notFound,
			});
		}
	});
}

const headerActions = $computed(() => [{
	text: i18n.ts.lookup,
	icon: 'fas fa-search',
	handler: find,
}, {
	text: i18n.ts.clearCachedFiles,
	icon: 'fas fa-trash-alt',
	handler: clear,
}]);

const headerTabs = $computed(() => []);

definePageMetadata(computed(() => ({
	title: i18n.ts.files,
	icon: 'fas fa-cloud',
})));
</script>

<style lang="scss" scoped>
.xrmjdkdw {
	margin: var(--margin);
}
</style>