2020-01-29 21:37:25 +02:00
|
|
|
<template>
|
2020-10-17 14:12:00 +03:00
|
|
|
<section class="_section">
|
|
|
|
<div class="_title"><Fa :icon="faBoxes"/> {{ $t('importAndExport') }}</div>
|
2020-01-29 21:37:25 +02:00
|
|
|
<div class="_content">
|
2020-10-17 14:12:00 +03:00
|
|
|
<MkSelect v-model:value="exportTarget">
|
2020-07-24 19:56:52 +03:00
|
|
|
<option value="notes">{{ $t('_exportOrImport.allNotes') }}</option>
|
|
|
|
<option value="following">{{ $t('_exportOrImport.followingList') }}</option>
|
|
|
|
<option value="user-lists">{{ $t('_exportOrImport.userLists') }}</option>
|
|
|
|
<option value="mute">{{ $t('_exportOrImport.muteList') }}</option>
|
|
|
|
<option value="blocking">{{ $t('_exportOrImport.blockingList') }}</option>
|
2020-10-17 14:12:00 +03:00
|
|
|
</MkSelect>
|
|
|
|
<MkButton inline @click="doExport()"><Fa :icon="faDownload"/> {{ $t('export') }}</MkButton>
|
|
|
|
<MkButton inline @click="doImport()" :disabled="!['following', 'user-lists'].includes(exportTarget)"><Fa :icon="faUpload"/> {{ $t('import') }}</MkButton>
|
2020-01-29 21:37:25 +02:00
|
|
|
</div>
|
2020-02-13 18:24:05 +02:00
|
|
|
<input ref="file" type="file" style="display: none;" @change="onChangeFile"/>
|
2020-01-29 21:37:25 +02:00
|
|
|
</section>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script lang="ts">
|
2020-10-17 14:12:00 +03:00
|
|
|
import { defineComponent } from 'vue';
|
2020-01-29 21:37:25 +02:00
|
|
|
import { faDownload, faUpload, faBoxes } from '@fortawesome/free-solid-svg-icons';
|
2020-10-17 14:12:00 +03:00
|
|
|
import MkButton from '@/components/ui/button.vue';
|
|
|
|
import MkSelect from '@/components/ui/select.vue';
|
|
|
|
import { apiUrl } from '@/config';
|
|
|
|
import * as os from '@/os';
|
2020-01-29 21:37:25 +02:00
|
|
|
|
2020-10-17 14:12:00 +03:00
|
|
|
export default defineComponent({
|
2020-01-29 21:37:25 +02:00
|
|
|
components: {
|
|
|
|
MkButton,
|
|
|
|
MkSelect,
|
|
|
|
},
|
|
|
|
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
exportTarget: 'notes',
|
|
|
|
faDownload, faUpload, faBoxes
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
methods: {
|
|
|
|
doExport() {
|
2020-10-17 14:12:00 +03:00
|
|
|
os.api(
|
2020-01-29 21:37:25 +02:00
|
|
|
this.exportTarget == 'notes' ? 'i/export-notes' :
|
|
|
|
this.exportTarget == 'following' ? 'i/export-following' :
|
|
|
|
this.exportTarget == 'blocking' ? 'i/export-blocking' :
|
|
|
|
this.exportTarget == 'user-lists' ? 'i/export-user-lists' :
|
2020-10-18 10:43:22 +03:00
|
|
|
this.exportTarget == 'mute' ? 'i/export-mute' :
|
2020-01-29 21:37:25 +02:00
|
|
|
null, {})
|
|
|
|
.then(() => {
|
2020-10-17 14:12:00 +03:00
|
|
|
os.dialog({
|
2020-01-29 21:37:25 +02:00
|
|
|
type: 'info',
|
|
|
|
text: this.$t('exportRequested')
|
|
|
|
});
|
|
|
|
}).catch((e: any) => {
|
2020-10-17 14:12:00 +03:00
|
|
|
os.dialog({
|
2020-01-29 21:37:25 +02:00
|
|
|
type: 'error',
|
|
|
|
text: e.message
|
|
|
|
});
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
doImport() {
|
|
|
|
(this.$refs.file as any).click();
|
|
|
|
},
|
|
|
|
|
|
|
|
onChangeFile() {
|
|
|
|
const [file] = Array.from((this.$refs.file as any).files);
|
|
|
|
|
|
|
|
const data = new FormData();
|
|
|
|
data.append('file', file);
|
|
|
|
data.append('i', this.$store.state.i.token);
|
|
|
|
|
2020-10-18 04:11:34 +03:00
|
|
|
const promise = fetch(apiUrl + '/drive/files/create', {
|
2020-01-29 21:37:25 +02:00
|
|
|
method: 'POST',
|
|
|
|
body: data
|
|
|
|
})
|
|
|
|
.then(response => response.json())
|
|
|
|
.then(f => {
|
|
|
|
this.reqImport(f);
|
|
|
|
});
|
2020-10-18 04:11:34 +03:00
|
|
|
os.promiseDialog(promise);
|
2020-01-29 21:37:25 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
reqImport(file) {
|
2020-10-17 14:12:00 +03:00
|
|
|
os.api(
|
2020-01-29 21:37:25 +02:00
|
|
|
this.exportTarget == 'following' ? 'i/import-following' :
|
|
|
|
this.exportTarget == 'user-lists' ? 'i/import-user-lists' :
|
|
|
|
null, {
|
|
|
|
fileId: file.id
|
|
|
|
}).then(() => {
|
2020-10-17 14:12:00 +03:00
|
|
|
os.dialog({
|
2020-01-29 21:37:25 +02:00
|
|
|
type: 'info',
|
|
|
|
text: this.$t('importRequested')
|
|
|
|
});
|
|
|
|
}).catch((e: any) => {
|
2020-10-17 14:12:00 +03:00
|
|
|
os.dialog({
|
2020-01-29 21:37:25 +02:00
|
|
|
type: 'error',
|
|
|
|
text: e.message
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
</script>
|