Move filemanager/ to frontend/

This commit is contained in:
Johannes Zellner
2023-07-12 14:22:58 +02:00
parent 9b6957b52f
commit caa160b3fd
518 changed files with 16 additions and 16 deletions
+100
View File
@@ -0,0 +1,100 @@
<template>
<div class="viewer">
<TextEditor ref="textEditor"
v-show="active === 'textEditor'"
:save-handler="saveHandler"
@close="onClose"
:tr="$t"
/>
<ImageViewer ref="imageViewer" v-show="active === 'imageViewer'" @close="onClose"/>
</div>
</template>
<script>
import { TextEditor, ImageViewer } from 'pankow';
import { createDirectoryModel } from '../models/DirectoryModel.js';
import { sanitize } from 'pankow/utils';
const API_ORIGIN = import.meta.env.VITE_API_ORIGIN ? 'https://' + import.meta.env.VITE_API_ORIGIN : '';
export default {
name: 'Viewer',
components: {
ImageViewer,
TextEditor
},
data() {
return {
resourceId: '',
resourceType: '',
item: null,
active: ''
};
},
methods: {
onClose() {
this.$router.go(-1);
},
async saveHandler(item, content) {
await this.directoryModel.save(this.filePath, content);
}
},
async mounted() {
this.resourceId = this.$route.params.resourceId;
this.resourceType = this.$route.params.type;
this.filePath = this.$route.params.filePath.join('/');
const fileName = this.$route.params.filePath[this.$route.params.filePath.length-1];
const parentDirectoryPath = sanitize(this.filePath.split('/').slice(0, -1).join('/'));
this.directoryModel = createDirectoryModel(API_ORIGIN, localStorage.token, (this.resourceType === 'volume' ? 'volumes/' : 'apps/') + this.resourceId);
const files = await this.directoryModel.listFiles(parentDirectoryPath);
this.item = files.find(i => i.fileName === fileName);
if (!this.item) {
console.log('File not found', this.filePath);
return;
}
if (this.$refs.imageViewer.canHandle(this.item)) {
// collect other files in directory for prev/next action
const otherSupportedEntries = files.filter((item) => this.$refs.imageViewer.canHandle(item)).map((item) => {
item.resourceUrl = `/viewer/${this.resourceType}/${this.resourceId}${item.folderPath}/${item.fileName}`;
item.fullFileUrl = this.directoryModel.getFileUrl(`${item.folderPath}/${item.fileName}`);
return item;
});
this.$refs.imageViewer.open(this.item, otherSupportedEntries);
this.active = 'imageViewer';
} else if (this.$refs.textEditor.canHandle(this.item)) {
const content = await this.directoryModel.getFile(this.filePath);
this.$refs.textEditor.open(this.item, content);
this.active = 'textEditor';
} else {
console.warn(`no editor or viewer found for ${this.item.mimeType}`, this.item);
this.active = '';
window.location.replace(this.directoryModel.getFileUrl(this.filePath));
}
}
};
</script>
<style scoped>
.viewer{
flex-grow: 1;
overflow: hidden;
height: 100%;
display: flex;
}
.main-view-col {
overflow: auto;
flex-grow: 1;
}
</style>