updated format and lint scripts and applied them
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
// make sure basePath doesn't end with /
|
||||
let { basePath } = require('../config/host.json');
|
||||
const urlChars = basePath.split('');
|
||||
let { basePath } = require('../config/host.json')
|
||||
const urlChars = basePath.split('')
|
||||
|
||||
if(basePath.length > 1 && urlChars.pop() === '/') {
|
||||
basePath = urlChars.join('');
|
||||
if (basePath.length > 1 && urlChars.pop() === '/') {
|
||||
basePath = urlChars.join('')
|
||||
}
|
||||
module.exports = basePath;
|
||||
module.exports = basePath
|
||||
|
||||
@@ -1,48 +1,52 @@
|
||||
const isOkDirPart = str => {
|
||||
if(str.length > 255 || str.length === 0) return false;
|
||||
const end = str.length - 1;
|
||||
for(let i = 0; i < str.length; i++) {
|
||||
const c = str.charCodeAt(i);
|
||||
if(!(c > 47 && c < 58) && // 0-9
|
||||
!(c > 64 && c < 91) && // A-Z
|
||||
!(c > 96 && c < 123) && // a-z
|
||||
!(c === 95) && !(c === 45) && // _ and -
|
||||
!((c === 46 || c === 32) && // period or space if not first or last
|
||||
i !== 0 && i !== end)) {
|
||||
return false;
|
||||
if (str.length > 255 || str.length === 0) return false
|
||||
const end = str.length - 1
|
||||
for (let i = 0; i < str.length; i++) {
|
||||
const c = str.charCodeAt(i)
|
||||
if (
|
||||
!(c > 47 && c < 58) && // 0-9
|
||||
!(c > 64 && c < 91) && // A-Z
|
||||
!(c > 96 && c < 123) && // a-z
|
||||
!(c === 95) &&
|
||||
!(c === 45) && // _ and -
|
||||
!(
|
||||
(c === 46 || c === 32) && // period or space if not first or last
|
||||
i !== 0 &&
|
||||
i !== end
|
||||
)
|
||||
) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true;
|
||||
};
|
||||
return true
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
|
||||
checkDir: dir => {
|
||||
if(typeof dir !== 'string') return false;
|
||||
dir = dir.trim();
|
||||
if(dir.length === 0) return 0;
|
||||
if(dir.indexOf('/') > -1) {
|
||||
dir = dir.split('/').filter(p => p.length !== 0);
|
||||
if(dir.length === 1) {
|
||||
if(!isOkDirPart(dir[0])) false;
|
||||
dir = dir[0];
|
||||
} else if(dir.length === 0) {
|
||||
dir = '';
|
||||
} else if(dir.some(part => !isOkDirPart(part))) {
|
||||
return false;
|
||||
if (typeof dir !== 'string') return false
|
||||
dir = dir.trim()
|
||||
if (dir.length === 0) return 0
|
||||
if (dir.indexOf('/') > -1) {
|
||||
dir = dir.split('/').filter(p => p.length !== 0)
|
||||
if (dir.length === 1) {
|
||||
if (!isOkDirPart(dir[0])) false
|
||||
dir = dir[0]
|
||||
} else if (dir.length === 0) {
|
||||
dir = ''
|
||||
} else if (dir.some(part => !isOkDirPart(part))) {
|
||||
return false
|
||||
}
|
||||
} else if(!isOkDirPart(dir)) {
|
||||
return false;
|
||||
} else if (!isOkDirPart(dir)) {
|
||||
return false
|
||||
}
|
||||
return Array.isArray(dir) ? dir.join('/') : dir;
|
||||
return Array.isArray(dir) ? dir.join('/') : dir
|
||||
},
|
||||
|
||||
checkName: name => {
|
||||
if(typeof name !== 'string') return false;
|
||||
name = name.trim();
|
||||
if(name.length === 0) return 0;
|
||||
if(!isOkDirPart(name)) return false;
|
||||
return name;
|
||||
if (typeof name !== 'string') return false
|
||||
name = name.trim()
|
||||
if (name.length === 0) return 0
|
||||
if (!isOkDirPart(name)) return false
|
||||
return name
|
||||
},
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,21 +1,21 @@
|
||||
const freezeSSR = selector => {
|
||||
const FrozenSSR = () => {
|
||||
let __html = '';
|
||||
let props = {};
|
||||
if(typeof document !== 'undefined') {
|
||||
let el = document.querySelector(selector);
|
||||
if(el) {
|
||||
__html = el.innerHTML;
|
||||
let __html = ''
|
||||
let props = {}
|
||||
if (typeof document !== 'undefined') {
|
||||
let el = document.querySelector(selector)
|
||||
if (el) {
|
||||
__html = el.innerHTML
|
||||
el.getAttributeNames().forEach(attr => {
|
||||
const attrKey = attr === 'class' ? 'className' : attr;
|
||||
props[attrKey] = el.getAttribute(attr);
|
||||
});
|
||||
}
|
||||
const attrKey = attr === 'class' ? 'className' : attr
|
||||
props[attrKey] = el.getAttribute(attr)
|
||||
})
|
||||
}
|
||||
}
|
||||
return <div {...props} dangerouslySetInnerHTML={{ __html }} />;
|
||||
};
|
||||
return <div {...props} dangerouslySetInnerHTML={{ __html }} />
|
||||
}
|
||||
|
||||
return { loading: FrozenSSR };
|
||||
};
|
||||
return { loading: FrozenSSR }
|
||||
}
|
||||
|
||||
export default freezeSSR;
|
||||
export default freezeSSR
|
||||
|
||||
@@ -1,36 +1,39 @@
|
||||
import fetch from 'isomorphic-unfetch';
|
||||
import parseSort from './parseSort';
|
||||
import getUrl from './getUrl';
|
||||
import getJwt from './getJwt';
|
||||
import fetch from 'isomorphic-unfetch'
|
||||
import parseSort from './parseSort'
|
||||
import getUrl from './getUrl'
|
||||
import getJwt from './getJwt'
|
||||
|
||||
export const $limit = 12; // number of docs per page
|
||||
export const select = ['id', 'name', 'updated', 'dir']
|
||||
.map((f, i) => ({ [`$select[${i}]`]: f }));
|
||||
export const $limit = 12 // number of docs per page
|
||||
export const select = ['id', 'name', 'updated', 'dir'].map((f, i) => ({
|
||||
[`$select[${i}]`]: f,
|
||||
}))
|
||||
|
||||
export const getDocs = async (q, jwt) => {
|
||||
const docsRes = await fetch(getUrl('docs', Boolean(jwt)) + q, {
|
||||
headers: { Authorization: jwt || getJwt() }
|
||||
}).catch(({ message }) => ({ ok: false, error: message }));
|
||||
if(docsRes.ok) {
|
||||
const res = await docsRes.json();
|
||||
const total = res.total || 0;
|
||||
const docs = res.data || [];
|
||||
return { docs, total };
|
||||
headers: { Authorization: jwt || getJwt() },
|
||||
}).catch(({ message }) => ({ ok: false, error: message }))
|
||||
if (docsRes.ok) {
|
||||
const res = await docsRes.json()
|
||||
const total = res.total || 0
|
||||
const docs = res.data || []
|
||||
return { docs, total }
|
||||
}
|
||||
return { total: 0, docs: [], error: docsRes.message };
|
||||
};
|
||||
return { total: 0, docs: [], error: docsRes.message }
|
||||
}
|
||||
|
||||
export const buildQ = q => {
|
||||
if(!q.$search) delete q.$search;
|
||||
if(!q.$skip) delete q.$skip;
|
||||
if (!q.$search) delete q.$search
|
||||
if (!q.$skip) delete q.$skip
|
||||
else {
|
||||
q.$skip = (q.$skip - 1) * $limit;
|
||||
q.$skip = (q.$skip - 1) * $limit
|
||||
}
|
||||
const $sort = parseSort(q.$sort ? q.$sort : 'updated:-1');
|
||||
delete q.$sort;
|
||||
select.forEach(sel => q = {...q, ...sel});
|
||||
q = { $limit, ...q };
|
||||
let url = Object.keys(q).map(k => `${k}=${encodeURIComponent(q[k])}`).join('&');
|
||||
url = `?${url}&${$sort}`;
|
||||
return url;
|
||||
};
|
||||
const $sort = parseSort(q.$sort ? q.$sort : 'updated:-1')
|
||||
delete q.$sort
|
||||
select.forEach(sel => (q = { ...q, ...sel }))
|
||||
q = { $limit, ...q }
|
||||
let url = Object.keys(q)
|
||||
.map(k => `${k}=${encodeURIComponent(q[k])}`)
|
||||
.join('&')
|
||||
url = `?${url}&${$sort}`
|
||||
return url
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
export default req => {
|
||||
if(req) return req.jwt;
|
||||
if(typeof window !== 'undefined') {
|
||||
return window.localStorage.getItem('jwt');
|
||||
if (req) return req.jwt
|
||||
if (typeof window !== 'undefined') {
|
||||
return window.localStorage.getItem('jwt')
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
const url = require('url');
|
||||
const urljoin = require('url-join');
|
||||
const basePath = require('./basePath');
|
||||
const { host, port, protocol } = require('../config/host.json');
|
||||
const url = require('url')
|
||||
const urljoin = require('url-join')
|
||||
const basePath = require('./basePath')
|
||||
const { host, port, protocol } = require('../config/host.json')
|
||||
|
||||
module.exports = (path, absolute) => {
|
||||
path = urljoin(basePath, path);
|
||||
if(!absolute) return path;
|
||||
path = urljoin(basePath, path)
|
||||
if (!absolute) return path
|
||||
return url.format({
|
||||
hostname: host,
|
||||
port,
|
||||
protocol,
|
||||
pathname: path,
|
||||
});
|
||||
};
|
||||
})
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
module.exports = {
|
||||
getKey: e => e.which || e.keyCode,
|
||||
isCtrlKey: key => key === 91 || key === 93 || key === 17
|
||||
};
|
||||
isCtrlKey: key => key === 91 || key === 93 || key === 17,
|
||||
}
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
export default ({ user }) => {
|
||||
return { user };
|
||||
};
|
||||
export default ({ user }) => {
|
||||
return { user }
|
||||
}
|
||||
|
||||
@@ -1,18 +1,19 @@
|
||||
export default sort => {
|
||||
let key, ascDesc;
|
||||
switch(typeof sort) {
|
||||
case 'object': {
|
||||
key = Object.keys(sort).pop();
|
||||
ascDesc = sort[key];
|
||||
break;
|
||||
let key, ascDesc
|
||||
switch (typeof sort) {
|
||||
case 'object': {
|
||||
key = Object.keys(sort).pop()
|
||||
ascDesc = sort[key]
|
||||
break
|
||||
}
|
||||
case 'string': {
|
||||
const parts = sort.split(':')
|
||||
key = parts[0]
|
||||
ascDesc = parts[1]
|
||||
break
|
||||
}
|
||||
default:
|
||||
break
|
||||
}
|
||||
case 'string': {
|
||||
const parts = sort.split(':');
|
||||
key = parts[0];
|
||||
ascDesc = parts[1];
|
||||
break;
|
||||
}
|
||||
default: break;
|
||||
}
|
||||
return `$sort[${key}]=${ascDesc}`;
|
||||
};
|
||||
return `$sort[${key}]=${ascDesc}`
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
const basePath = require('./basePath');
|
||||
const basePath = require('./basePath')
|
||||
|
||||
module.exports = url => {
|
||||
if(basePath !== '/') {
|
||||
url = url.split(basePath).join('');
|
||||
if (basePath !== '/') {
|
||||
url = url.split(basePath).join('')
|
||||
}
|
||||
return url;
|
||||
};
|
||||
return url
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
export default function updateStateFromId(e){
|
||||
const el = e.target;
|
||||
this.setState({ [el.id]: el.value });
|
||||
}
|
||||
export default function updateStateFromId(e) {
|
||||
const el = e.target
|
||||
this.setState({ [el.id]: el.value })
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user