Modify upload function to accept only yml files on folder upload. Adding breadcrumbs, adding feature to create folder
This commit is contained in:
parent
fe715360a5
commit
16c4455d8d
@ -2,21 +2,34 @@
|
|||||||
<nav :class="{ active }">
|
<nav :class="{ active }">
|
||||||
<template v-if="isLogged">
|
<template v-if="isLogged">
|
||||||
<router-link
|
<router-link
|
||||||
class="action"
|
class="action"
|
||||||
to="/files/"
|
to="/files/"
|
||||||
:aria-label="$t('sidebar.myFiles')"
|
:aria-label="$t('sidebar.myFiles')"
|
||||||
:title="$t('sidebar.myFiles')"
|
:title="$t('sidebar.myFiles')"
|
||||||
>
|
>
|
||||||
<i class="material-icons">folder</i>
|
<i class="material-icons">folder</i>
|
||||||
<span>{{ $t("sidebar.myFiles") }}</span>
|
<span>{{ $t("sidebar.myFiles") }}</span>
|
||||||
</router-link>
|
</router-link>
|
||||||
|
|
||||||
<div v-if="user.perm.create">
|
<div v-if="user.perm.create">
|
||||||
<button
|
<button
|
||||||
@click="$store.commit('showHover', 'newFile')"
|
@click="$store.commit('showHover', 'newDir')"
|
||||||
class="action"
|
class="action"
|
||||||
:aria-label="$t('sidebar.newFile')"
|
:aria-label="$t('sidebar.newFolder')"
|
||||||
:title="$t('sidebar.newFile')"
|
:title="$t('sidebar.newFolder')"
|
||||||
|
>
|
||||||
|
<i class="material-icons">create_new_folder</i>
|
||||||
|
<span>{{ $t("sidebar.newFolder") }}</span>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
<div v-if="user.perm.create">
|
||||||
|
<button
|
||||||
|
@click="$store.commit('showHover', 'newFile')"
|
||||||
|
class="action"
|
||||||
|
:aria-label="$t('sidebar.newFile')"
|
||||||
|
:title="$t('sidebar.newFile')"
|
||||||
>
|
>
|
||||||
<i class="material-icons">note_add</i>
|
<i class="material-icons">note_add</i>
|
||||||
<span>{{ $t("sidebar.newFile") }}</span>
|
<span>{{ $t("sidebar.newFile") }}</span>
|
||||||
@ -28,9 +41,9 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import { mapGetters, mapState } from "vuex";
|
import {mapGetters, mapState} from "vuex";
|
||||||
import * as auth from "@/utils/auth";
|
import * as auth from "@/utils/auth";
|
||||||
import { authMethod, disableExternal, noAuth, signup, version } from "@/utils/constants";
|
import {authMethod, disableExternal, noAuth, signup, version} from "@/utils/constants";
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: "sidebar",
|
name: "sidebar",
|
||||||
|
|||||||
@ -112,7 +112,7 @@
|
|||||||
width: 100%;
|
width: 100%;
|
||||||
max-width: 100%;
|
max-width: 100%;
|
||||||
margin: 0;
|
margin: 0;
|
||||||
margin-top: 64px;
|
margin-top: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
#listing.list .item {
|
#listing.list .item {
|
||||||
|
|||||||
@ -2,126 +2,132 @@ import store from "@/store";
|
|||||||
import url from "@/utils/url";
|
import url from "@/utils/url";
|
||||||
|
|
||||||
export function checkConflict(files, items) {
|
export function checkConflict(files, items) {
|
||||||
if (typeof items === "undefined" || items === null) {
|
if (typeof items === "undefined" || items === null) {
|
||||||
items = [];
|
items = [];
|
||||||
}
|
|
||||||
|
|
||||||
let folder_upload = files[0].fullPath !== undefined;
|
|
||||||
|
|
||||||
let conflict = false;
|
|
||||||
for (let i = 0; i < files.length; i++) {
|
|
||||||
let file = files[i];
|
|
||||||
let name = file.name;
|
|
||||||
|
|
||||||
if (folder_upload) {
|
|
||||||
let dirs = file.fullPath.split("/");
|
|
||||||
if (dirs.length > 1) {
|
|
||||||
name = dirs[0];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let res = items.findIndex(function hasConflict(element) {
|
let folder_upload = files[0].fullPath !== undefined;
|
||||||
return element.name === this;
|
|
||||||
}, name);
|
|
||||||
|
|
||||||
if (res >= 0) {
|
let conflict = false;
|
||||||
conflict = true;
|
for (let i = 0; i < files.length; i++) {
|
||||||
break;
|
let file = files[i];
|
||||||
|
let name = file.name;
|
||||||
|
|
||||||
|
if (folder_upload) {
|
||||||
|
let dirs = file.fullPath.split("/");
|
||||||
|
if (dirs.length > 1) {
|
||||||
|
name = dirs[0];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let res = items.findIndex(function hasConflict(element) {
|
||||||
|
return element.name === this;
|
||||||
|
}, name);
|
||||||
|
|
||||||
|
if (res >= 0) {
|
||||||
|
conflict = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return conflict;
|
return conflict;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function scanFiles(dt) {
|
export function scanFiles(dt) {
|
||||||
return new Promise((resolve) => {
|
return new Promise((resolve) => {
|
||||||
let reading = 0;
|
let reading = 0;
|
||||||
const contents = [];
|
const contents = [];
|
||||||
|
|
||||||
if (dt.items !== undefined) {
|
if (dt.items !== undefined) {
|
||||||
for (let item of dt.items) {
|
for (let item of dt.items) {
|
||||||
if (
|
if (
|
||||||
item.kind === "file" &&
|
item.kind === "file" &&
|
||||||
typeof item.webkitGetAsEntry === "function"
|
typeof item.webkitGetAsEntry === "function"
|
||||||
) {
|
) {
|
||||||
const entry = item.webkitGetAsEntry();
|
const entry = item.webkitGetAsEntry();
|
||||||
readEntry(entry);
|
readEntry(entry);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
resolve(dt.files);
|
resolve(dt.files);
|
||||||
}
|
|
||||||
|
|
||||||
function readEntry(entry, directory = "") {
|
|
||||||
if (entry.isFile) {
|
|
||||||
reading++;
|
|
||||||
entry.file((file) => {
|
|
||||||
reading--;
|
|
||||||
|
|
||||||
file.fullPath = `${directory}${file.name}`;
|
|
||||||
contents.push(file);
|
|
||||||
|
|
||||||
if (reading === 0) {
|
|
||||||
resolve(contents);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
} else if (entry.isDirectory) {
|
|
||||||
const dir = {
|
|
||||||
isDir: true,
|
|
||||||
size: 0,
|
|
||||||
fullPath: `${directory}${entry.name}`,
|
|
||||||
};
|
|
||||||
|
|
||||||
contents.push(dir);
|
|
||||||
|
|
||||||
readReaderContent(entry.createReader(), `${directory}${entry.name}`);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function readReaderContent(reader, directory) {
|
|
||||||
reading++;
|
|
||||||
|
|
||||||
reader.readEntries(function (entries) {
|
|
||||||
reading--;
|
|
||||||
if (entries.length > 0) {
|
|
||||||
for (const entry of entries) {
|
|
||||||
readEntry(entry, `${directory}/`);
|
|
||||||
}
|
|
||||||
|
|
||||||
readReaderContent(reader, `${directory}/`);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (reading === 0) {
|
function readEntry(entry, directory = "") {
|
||||||
resolve(contents);
|
if (entry.isFile) {
|
||||||
|
reading++;
|
||||||
|
entry.file((file) => {
|
||||||
|
reading--;
|
||||||
|
|
||||||
|
file.fullPath = `${directory}${file.name}`;
|
||||||
|
contents.push(file);
|
||||||
|
|
||||||
|
if (reading === 0) {
|
||||||
|
resolve(contents);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} else if (entry.isDirectory) {
|
||||||
|
const dir = {
|
||||||
|
isDir: true,
|
||||||
|
size: 0,
|
||||||
|
fullPath: `${directory}${entry.name}`,
|
||||||
|
};
|
||||||
|
|
||||||
|
contents.push(dir);
|
||||||
|
|
||||||
|
readReaderContent(entry.createReader(), `${directory}${entry.name}`);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
|
||||||
}
|
function readReaderContent(reader, directory) {
|
||||||
});
|
reading++;
|
||||||
|
|
||||||
|
reader.readEntries(function (entries) {
|
||||||
|
reading--;
|
||||||
|
if (entries.length > 0) {
|
||||||
|
for (const entry of entries) {
|
||||||
|
readEntry(entry, `${directory}/`);
|
||||||
|
}
|
||||||
|
|
||||||
|
readReaderContent(reader, `${directory}/`);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (reading === 0) {
|
||||||
|
resolve(contents);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
export function handleFiles(files, base, overwrite = false) {
|
export function handleFiles(files, base, overwrite = false) {
|
||||||
for (let i = 0; i < files.length; i++) {
|
for (let i = 0; i < files.length; i++) {
|
||||||
let id = store.state.upload.id;
|
|
||||||
let path = base;
|
|
||||||
let file = files[i];
|
|
||||||
|
|
||||||
if (file.fullPath !== undefined) {
|
let id = store.state.upload.id;
|
||||||
path += url.encodePath(file.fullPath);
|
let path = base;
|
||||||
} else {
|
let file = files[i];
|
||||||
path += url.encodeRFC5987ValueChars(file.name);
|
console.log(file);
|
||||||
|
var re = /(?:\.([^.]+))?$/;
|
||||||
|
console.log(re.exec(file.name)[1]);
|
||||||
|
if (re.exec(file.name)[1] === 'yml') {
|
||||||
|
console.log('Is yml file')
|
||||||
|
if (file.fullPath !== undefined) {
|
||||||
|
path += url.encodePath(file.fullPath);
|
||||||
|
} else {
|
||||||
|
path += url.encodeRFC5987ValueChars(file.name);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (file.isDir) {
|
||||||
|
path += "/";
|
||||||
|
}
|
||||||
|
|
||||||
|
const item = {
|
||||||
|
id,
|
||||||
|
path,
|
||||||
|
file,
|
||||||
|
overwrite,
|
||||||
|
};
|
||||||
|
|
||||||
|
store.dispatch("upload/upload", item);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (file.isDir) {
|
|
||||||
path += "/";
|
|
||||||
}
|
|
||||||
|
|
||||||
const item = {
|
|
||||||
id,
|
|
||||||
path,
|
|
||||||
file,
|
|
||||||
overwrite,
|
|
||||||
};
|
|
||||||
|
|
||||||
store.dispatch("upload/upload", item);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
<template>
|
<template>
|
||||||
<div>
|
<div>
|
||||||
<header-bar v-if="error || req.type == null" showMenu showLogo />
|
<header-bar v-if="error || req.type == null" showMenu showLogo />
|
||||||
|
<breadcrumbs base="/files" />
|
||||||
<errors v-if="error" :errorCode="error.message" />
|
<errors v-if="error" :errorCode="error.message" />
|
||||||
<component v-else-if="currentView" :is="currentView"></component>
|
<component v-else-if="currentView" :is="currentView"></component>
|
||||||
<div v-else>
|
<div v-else>
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user