chore: add prettier frontent linter

This commit is contained in:
Oleg Lobanov
2021-03-21 12:51:58 +01:00
parent a721dc1f31
commit c44b37c50c
73 changed files with 18898 additions and 4499 deletions

View File

@@ -1,88 +1,88 @@
import store from '@/store'
import router from '@/router'
import { Base64 } from 'js-base64'
import { baseURL } from '@/utils/constants'
import store from "@/store";
import router from "@/router";
import { Base64 } from "js-base64";
import { baseURL } from "@/utils/constants";
export function parseToken (token) {
const parts = token.split('.')
export function parseToken(token) {
const parts = token.split(".");
if (parts.length !== 3) {
throw new Error('token malformed')
throw new Error("token malformed");
}
const data = JSON.parse(Base64.decode(parts[1]))
const data = JSON.parse(Base64.decode(parts[1]));
localStorage.setItem('jwt', token)
store.commit('setJWT', token)
store.commit('setUser', data.user)
localStorage.setItem("jwt", token);
store.commit("setJWT", token);
store.commit("setUser", data.user);
}
export async function validateLogin () {
export async function validateLogin() {
try {
if (localStorage.getItem('jwt')) {
await renew(localStorage.getItem('jwt'))
if (localStorage.getItem("jwt")) {
await renew(localStorage.getItem("jwt"));
}
} catch (_) {
console.warn('Invalid JWT token in storage') // eslint-disable-line
}
}
export async function login (username, password, recaptcha) {
const data = { username, password, recaptcha }
export async function login(username, password, recaptcha) {
const data = { username, password, recaptcha };
const res = await fetch(`${baseURL}/api/login`, {
method: 'POST',
method: "POST",
headers: {
'Content-Type': 'application/json'
"Content-Type": "application/json",
},
body: JSON.stringify(data)
})
body: JSON.stringify(data),
});
const body = await res.text()
const body = await res.text();
if (res.status === 200) {
parseToken(body)
parseToken(body);
} else {
throw new Error(body)
throw new Error(body);
}
}
export async function renew (jwt) {
export async function renew(jwt) {
const res = await fetch(`${baseURL}/api/renew`, {
method: 'POST',
method: "POST",
headers: {
'X-Auth': jwt,
}
})
"X-Auth": jwt,
},
});
const body = await res.text()
const body = await res.text();
if (res.status === 200) {
parseToken(body)
parseToken(body);
} else {
throw new Error(body)
throw new Error(body);
}
}
export async function signup (username, password) {
const data = { username, password }
export async function signup(username, password) {
const data = { username, password };
const res = await fetch(`${baseURL}/api/signup`, {
method: 'POST',
method: "POST",
headers: {
'Content-Type': 'application/json'
"Content-Type": "application/json",
},
body: JSON.stringify(data)
})
body: JSON.stringify(data),
});
if (res.status !== 200) {
throw new Error(res.status)
throw new Error(res.status);
}
}
export function logout () {
store.commit('setJWT', '')
store.commit('setUser', null)
localStorage.setItem('jwt', null)
router.push({path: '/login'})
export function logout() {
store.commit("setJWT", "");
store.commit("setUser", null);
localStorage.setItem("jwt", null);
router.push({ path: "/login" });
}

View File

@@ -1,70 +1,70 @@
function loading (button) {
let el = document.querySelector(`#${button}-button > i`)
function loading(button) {
let el = document.querySelector(`#${button}-button > i`);
if (el === undefined || el === null) {
console.log('Error getting button ' + button) // eslint-disable-line
return
return;
}
if (el.innerHTML == 'autorenew' || el.innerHTML == 'done') {
return
if (el.innerHTML == "autorenew" || el.innerHTML == "done") {
return;
}
el.dataset.icon = el.innerHTML
el.style.opacity = 0
el.dataset.icon = el.innerHTML;
el.style.opacity = 0;
setTimeout(() => {
el.classList.add('spin')
el.innerHTML = 'autorenew'
el.style.opacity = 1
}, 100)
el.classList.add("spin");
el.innerHTML = "autorenew";
el.style.opacity = 1;
}, 100);
}
function done (button) {
let el = document.querySelector(`#${button}-button > i`)
function done(button) {
let el = document.querySelector(`#${button}-button > i`);
if (el === undefined || el === null) {
console.log('Error getting button ' + button) // eslint-disable-line
return
return;
}
el.style.opacity = 0
el.style.opacity = 0;
setTimeout(() => {
el.classList.remove('spin')
el.innerHTML = el.dataset.icon
el.style.opacity = 1
}, 100)
el.classList.remove("spin");
el.innerHTML = el.dataset.icon;
el.style.opacity = 1;
}, 100);
}
function success (button) {
let el = document.querySelector(`#${button}-button > i`)
function success(button) {
let el = document.querySelector(`#${button}-button > i`);
if (el === undefined || el === null) {
console.log('Error getting button ' + button) // eslint-disable-line
return
return;
}
el.style.opacity = 0
el.style.opacity = 0;
setTimeout(() => {
el.classList.remove('spin')
el.innerHTML = 'done'
el.style.opacity = 1
el.classList.remove("spin");
el.innerHTML = "done";
el.style.opacity = 1;
setTimeout(() => {
el.style.opacity = 0
el.style.opacity = 0;
setTimeout(() => {
el.innerHTML = el.dataset.icon
el.style.opacity = 1
}, 100)
}, 500)
}, 100)
el.innerHTML = el.dataset.icon;
el.style.opacity = 1;
}, 100);
}, 500);
}, 100);
}
export default {
loading,
done,
success
}
success,
};

View File

@@ -1,19 +1,19 @@
const name = window.FileBrowser.Name || 'File Browser'
const disableExternal = window.FileBrowser.DisableExternal
const baseURL = window.FileBrowser.BaseURL
const staticURL = window.FileBrowser.StaticURL
const recaptcha = window.FileBrowser.ReCaptcha
const recaptchaKey = window.FileBrowser.ReCaptchaKey
const signup = window.FileBrowser.Signup
const version = window.FileBrowser.Version
const logoURL = `${staticURL}/img/logo.svg`
const noAuth = window.FileBrowser.NoAuth
const authMethod = window.FileBrowser.AuthMethod
const loginPage = window.FileBrowser.LoginPage
const theme = window.FileBrowser.Theme
const enableThumbs = window.FileBrowser.EnableThumbs
const resizePreview = window.FileBrowser.ResizePreview
const enableExec = window.FileBrowser.EnableExec
const name = window.FileBrowser.Name || "File Browser";
const disableExternal = window.FileBrowser.DisableExternal;
const baseURL = window.FileBrowser.BaseURL;
const staticURL = window.FileBrowser.StaticURL;
const recaptcha = window.FileBrowser.ReCaptcha;
const recaptchaKey = window.FileBrowser.ReCaptchaKey;
const signup = window.FileBrowser.Signup;
const version = window.FileBrowser.Version;
const logoURL = `${staticURL}/img/logo.svg`;
const noAuth = window.FileBrowser.NoAuth;
const authMethod = window.FileBrowser.AuthMethod;
const loginPage = window.FileBrowser.LoginPage;
const theme = window.FileBrowser.Theme;
const enableThumbs = window.FileBrowser.EnableThumbs;
const resizePreview = window.FileBrowser.ResizePreview;
const enableExec = window.FileBrowser.EnableExec;
export {
name,
@@ -30,5 +30,5 @@ export {
theme,
enableThumbs,
resizePreview,
enableExec
}
enableExec,
};

View File

@@ -1,4 +1,6 @@
export default function (name) {
let re = new RegExp('(?:(?:^|.*;\\s*)' + name + '\\s*\\=\\s*([^;]*).*$)|^.*$')
return document.cookie.replace(re, '$1')
let re = new RegExp(
"(?:(?:^|.*;\\s*)" + name + "\\s*\\=\\s*([^;]*).*$)|^.*$"
);
return document.cookie.replace(re, "$1");
}

View File

@@ -1,28 +1,28 @@
export default function getRule (rules) {
export default function getRule(rules) {
for (let i = 0; i < rules.length; i++) {
rules[i] = rules[i].toLowerCase()
rules[i] = rules[i].toLowerCase();
}
let result = null
let find = Array.prototype.find
let result = null;
let find = Array.prototype.find;
find.call(document.styleSheets, styleSheet => {
result = find.call(styleSheet.cssRules, cssRule => {
let found = false
find.call(document.styleSheets, (styleSheet) => {
result = find.call(styleSheet.cssRules, (cssRule) => {
let found = false;
if (cssRule instanceof window.CSSStyleRule) {
for (let i = 0; i < rules.length; i++) {
if (cssRule.selectorText.toLowerCase() === rules[i]) {
found = true
found = true;
}
}
}
return found
})
return found;
});
return result != null
})
return result != null;
});
return result
return result;
}

View File

@@ -1,124 +1,127 @@
import store from '@/store'
import url from '@/utils/url'
import store from "@/store";
import url from "@/utils/url";
export function checkConflict(files, items) {
if (typeof items === 'undefined' || items === null) {
items = []
if (typeof items === "undefined" || items === null) {
items = [];
}
let folder_upload = files[0].fullPath !== undefined
let folder_upload = files[0].fullPath !== undefined;
let conflict = false
let conflict = false;
for (let i = 0; i < files.length; i++) {
let file = files[i]
let name = file.name
let file = files[i];
let name = file.name;
if (folder_upload) {
let dirs = file.fullPath.split("/")
let dirs = file.fullPath.split("/");
if (dirs.length > 1) {
name = dirs[0]
name = dirs[0];
}
}
let res = items.findIndex(function hasConflict(element) {
return (element.name === this)
}, name)
return element.name === this;
}, name);
if (res >= 0) {
conflict = true
break
conflict = true;
break;
}
}
return conflict
return conflict;
}
export function scanFiles(dt) {
return new Promise((resolve) => {
let reading = 0
const contents = []
let reading = 0;
const contents = [];
if (dt.items !== undefined) {
for (let item of dt.items) {
if (item.kind === "file" && typeof item.webkitGetAsEntry === "function") {
const entry = item.webkitGetAsEntry()
readEntry(entry)
if (
item.kind === "file" &&
typeof item.webkitGetAsEntry === "function"
) {
const entry = item.webkitGetAsEntry();
readEntry(entry);
}
}
} else {
resolve(dt.files)
resolve(dt.files);
}
function readEntry(entry, directory = "") {
if (entry.isFile) {
reading++
entry.file(file => {
reading--
reading++;
entry.file((file) => {
reading--;
file.fullPath = `${directory}${file.name}`
contents.push(file)
file.fullPath = `${directory}${file.name}`;
contents.push(file);
if (reading === 0) {
resolve(contents)
resolve(contents);
}
})
});
} else if (entry.isDirectory) {
const dir = {
isDir: true,
size: 0,
fullPath: `${directory}${entry.name}`
}
fullPath: `${directory}${entry.name}`,
};
contents.push(dir)
contents.push(dir);
readReaderContent(entry.createReader(), `${directory}${entry.name}`)
readReaderContent(entry.createReader(), `${directory}${entry.name}`);
}
}
function readReaderContent(reader, directory) {
reading++
reading++;
reader.readEntries(function (entries) {
reading--
reading--;
if (entries.length > 0) {
for (const entry of entries) {
readEntry(entry, `${directory}/`)
readEntry(entry, `${directory}/`);
}
readReaderContent(reader, `${directory}/`)
readReaderContent(reader, `${directory}/`);
}
if (reading === 0) {
resolve(contents)
resolve(contents);
}
})
});
}
})
});
}
export function handleFiles(files, base, overwrite = false) {
for (let i = 0; i < files.length; i++) {
let id = store.state.upload.id
let path = base
let file = files[i]
let id = store.state.upload.id;
let path = base;
let file = files[i];
if (file.fullPath !== undefined) {
path += url.encodePath(file.fullPath)
path += url.encodePath(file.fullPath);
} else {
path += url.encodeRFC5987ValueChars(file.name)
path += url.encodeRFC5987ValueChars(file.name);
}
if (file.isDir) {
path += '/'
path += "/";
}
const item = {
id,
path,
file,
overwrite
}
overwrite,
};
store.dispatch('upload/upload', item);
store.dispatch("upload/upload", item);
}
}
}

View File

@@ -1,31 +1,36 @@
function removeLastDir (url) {
var arr = url.split('/')
if (arr.pop() === '') {
arr.pop()
function removeLastDir(url) {
var arr = url.split("/");
if (arr.pop() === "") {
arr.pop();
}
return arr.join('/')
return arr.join("/");
}
// this code borrow from mozilla
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/encodeURIComponent#Examples
function encodeRFC5987ValueChars(str) {
return encodeURIComponent(str).
return (
encodeURIComponent(str)
// Note that although RFC3986 reserves "!", RFC5987 does not,
// so we do not need to escape it
replace(/['()]/g, escape). // i.e., %27 %28 %29
replace(/\*/g, '%2A').
// The following are not required for percent-encoding per RFC5987,
// so we can allow for a little better readability over the wire: |`^
replace(/%(?:7C|60|5E)/g, unescape);
.replace(/['()]/g, escape) // i.e., %27 %28 %29
.replace(/\*/g, "%2A")
// The following are not required for percent-encoding per RFC5987,
// so we can allow for a little better readability over the wire: |`^
.replace(/%(?:7C|60|5E)/g, unescape)
);
}
function encodePath(str) {
return str.split('/').map(v => encodeURIComponent(v)).join('/')
return str
.split("/")
.map((v) => encodeURIComponent(v))
.join("/");
}
export default {
encodeRFC5987ValueChars: encodeRFC5987ValueChars,
removeLastDir: removeLastDir,
encodePath: encodePath
}
encodePath: encodePath,
};

View File

@@ -1,58 +1,66 @@
import Vue from 'vue'
import Noty from 'noty'
import VueLazyload from 'vue-lazyload'
import i18n from '@/i18n'
import { disableExternal } from '@/utils/constants'
import Vue from "vue";
import Noty from "noty";
import VueLazyload from "vue-lazyload";
import i18n from "@/i18n";
import { disableExternal } from "@/utils/constants";
Vue.use(VueLazyload)
Vue.use(VueLazyload);
Vue.config.productionTip = true
Vue.config.productionTip = true;
const notyDefault = {
type: 'info',
layout: 'bottomRight',
type: "info",
layout: "bottomRight",
timeout: 1000,
progressBar: true
}
progressBar: true,
};
Vue.prototype.$noty = (opts) => {
new Noty(Object.assign({}, notyDefault, opts)).show()
}
new Noty(Object.assign({}, notyDefault, opts)).show();
};
Vue.prototype.$showSuccess = (message) => {
new Noty(Object.assign({}, notyDefault, {
text: message,
type: 'success'
})).show()
}
new Noty(
Object.assign({}, notyDefault, {
text: message,
type: "success",
})
).show();
};
Vue.prototype.$showError = (error, displayReport = true) => {
let btns = [
Noty.button(i18n.t('buttons.close'), '', function () {
n.close()
})
]
Noty.button(i18n.t("buttons.close"), "", function () {
n.close();
}),
];
if (!disableExternal && displayReport) {
btns.unshift(Noty.button(i18n.t('buttons.reportIssue'), '', function () {
window.open('https://github.com/filebrowser/filebrowser/issues/new/choose')
}))
btns.unshift(
Noty.button(i18n.t("buttons.reportIssue"), "", function () {
window.open(
"https://github.com/filebrowser/filebrowser/issues/new/choose"
);
})
);
}
let n = new Noty(Object.assign({}, notyDefault, {
text: error.message || error,
type: 'error',
timeout: null,
buttons: btns
}))
let n = new Noty(
Object.assign({}, notyDefault, {
text: error.message || error,
type: "error",
timeout: null,
buttons: btns,
})
);
n.show()
}
n.show();
};
Vue.directive('focus', {
Vue.directive("focus", {
inserted: function (el) {
el.focus()
}
})
el.focus();
},
});
export default Vue
export default Vue;