1
0
Fork 0
mirror of https://github.com/muerwre/vault-frontend.git synced 2025-04-25 04:46:40 +07:00

flow get more

This commit is contained in:
Fedor Katurov 2019-11-18 14:49:32 +07:00
parent f440a5f4c3
commit 971578bb21
11 changed files with 281 additions and 159 deletions

View file

@ -1,19 +1,23 @@
import { IFile } from '~/redux/types';
import formatDistanceToNow from 'date-fns/formatDistanceToNow';
import { ru } from 'date-fns/locale';
import Axios from 'axios';
import { PRESETS } from '~/constants/urls';
import { IFile } from "~/redux/types";
import formatDistanceToNow from "date-fns/formatDistanceToNow";
import { ru } from "date-fns/locale";
import Axios from "axios";
import { PRESETS } from "~/constants/urls";
export const getStyle = (oElm: any, strCssRule: string) => {
if (document.defaultView && document.defaultView.getComputedStyle) {
return document.defaultView.getComputedStyle(oElm, '').getPropertyValue(strCssRule);
return document.defaultView
.getComputedStyle(oElm, "")
.getPropertyValue(strCssRule);
}
if (oElm.currentStyle) {
return oElm.currentStyle[strCssRule.replace(/-(\w)/g, (strMatch, p1) => p1.toUpperCase())];
return oElm.currentStyle[
strCssRule.replace(/-(\w)/g, (strMatch, p1) => p1.toUpperCase())
];
}
return '';
return "";
};
function polarToCartesian(centerX, centerY, radius, angleInDegrees) {
@ -21,7 +25,7 @@ function polarToCartesian(centerX, centerY, radius, angleInDegrees) {
return {
x: centerX + radius * Math.cos(angleInRadians),
y: centerY + radius * Math.sin(angleInRadians),
y: centerY + radius * Math.sin(angleInRadians)
};
}
@ -38,10 +42,10 @@ export const describeArc = (
const largeArcFlag = endAngle - startAngle <= 180 ? 0 : 1;
return [
'M',
"M",
start.x,
start.y,
'A',
"A",
radius,
radius,
0,
@ -49,63 +53,76 @@ export const describeArc = (
0,
end.x,
end.y,
'L',
"L",
x,
y,
'L',
"L",
start.x,
start.y,
].join(' ');
start.y
].join(" ");
};
export const getURL = (file: Partial<IFile>, size?: typeof PRESETS[keyof typeof PRESETS]) => {
export const getURL = (
file: Partial<IFile>,
size?: typeof PRESETS[keyof typeof PRESETS]
) => {
if (!file || !file.url) return null;
if (size) {
return file.url
.replace('REMOTE_CURRENT://', `${process.env.REMOTE_CURRENT}cache/${size}/`)
.replace('REMOTE_OLD://', process.env.REMOTE_OLD);
.replace(
"REMOTE_CURRENT://",
`${process.env.REMOTE_CURRENT}cache/${size}/`
)
.replace("REMOTE_OLD://", process.env.REMOTE_OLD);
}
return file.url
.replace('REMOTE_CURRENT://', process.env.REMOTE_CURRENT)
.replace('REMOTE_OLD://', process.env.REMOTE_OLD);
.replace("REMOTE_CURRENT://", process.env.REMOTE_CURRENT)
.replace("REMOTE_OLD://", process.env.REMOTE_OLD);
};
export const formatText = (text: string): string =>
!text
? ''
? ""
: text
.replace(/(\n{2,})/gi, '\n')
.replace(/</g, '&lt;')
.replace(/>/g, '&gt;')
.replace(/\n{1,}/gim, "\n")
.replace(/</g, "&lt;")
.replace(/>/g, "&gt;")
.replace(
/~([\wа-яА-Я\-]+)/giu,
'<span class="username" onClick="window.postMessage({ type: \'username\', username: \'$1\'});">~$1</span>'
"<span class=\"username\" onClick=\"window.postMessage({ type: 'username', username: '$1'});\">~$1</span>"
)
.replace(/:\/\//gim, ':|--|')
.replace(/:\/\//gim, ":|--|")
.replace(/(\/\/[^\n]+)/gim, '<span class="grey">$1</span>')
.replace(/(\/\*[\s\S]*?\*\/)/gim, '<span class="grey">$1</span>')
.replace(/:\|--\|/gim, '://')
.split('\n')
.replace(/:\|--\|/gim, "://")
.split("\n")
.filter(el => el.trim().length)
.map(el => `<p>${el}</p>`)
.join('');
.join("");
export const formatCommentText = (author: string, text: string): string =>
text
? formatText(text).replace(
/^<p>/,
author ? `<p><b class="comment-author">${author}: </b>` : '<p>'
author ? `<p><b class="comment-author">${author}: </b>` : "<p>"
)
: '';
: "";
export const formatCellText = (text: string): string => formatText(text);
export const getPrettyDate = (date: string): string =>
formatDistanceToNow(new Date(date), { locale: ru, includeSeconds: true, addSuffix: true });
formatDistanceToNow(new Date(date), {
locale: ru,
includeSeconds: true,
addSuffix: true
});
export const getYoutubeTitle = async (id: string) => {
Axios.get(`http://youtube.com/get_video_info?video_id=${id}`).then(console.log);
Axios.get(`http://youtube.com/get_video_info?video_id=${id}`).then(
console.log
);
};
(<any>window).getYoutubeTitle = getYoutubeTitle;