file component and lib updated
This commit is contained in:
1 parent
b50b4b3ab3
commit
1756d89cb4
2 files changed
+20
-13
No files matched your search
+9
-3
@@ -9,6 +9,7 @@ import { createApiUrl, requestGet, IResponseItems } from 'src/next-lib'
|
||||
import { NextPage } from 'next'
|
||||
import { IBreadcumbsPart, IMeta, IPage, ITag, FileTokenData, Token } from 'src/types'
|
||||
import { joinTokens } from 'src/lib/tokens'
|
||||
import { size, ext } from 'src/lib/file'
|
||||
import { Html } from 'src/components/Html'
|
||||
|
||||
function array<T>(value: T | T[]) {
|
||||
@@ -37,7 +38,11 @@ const Youtube: React.SFC<{ url: string }> = props => {
|
||||
)
|
||||
}
|
||||
|
||||
const File: React.SFC<FileTokenData> = props => (
|
||||
const File: React.SFC<FileTokenData> = props => {
|
||||
const fileSize = size(props.file_size)
|
||||
const format = ext(props.file_format)
|
||||
|
||||
return (
|
||||
<div className="document-row">
|
||||
<a href={props['url']} className="invisible">
|
||||
<div className="document-row__image">
|
||||
@@ -50,12 +55,13 @@ const File: React.SFC<FileTokenData> = props => (
|
||||
</div>
|
||||
|
||||
<div className="document-row__file-info">
|
||||
<a href="document['file_url']" target="_blank">
|
||||
{props.file_format} ({props.file_size})
|
||||
<a href={props.file_url} target="_blank">
|
||||
{format} ({fileSize})
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
type Props = {
|
||||
title: string
|
||||
|
||||
+11
-10
@@ -1,16 +1,17 @@
|
||||
const getExt = (name: string) => /\.(\w+)$/.exec(name)[1]
|
||||
const defaultExt = (ext: string) => ext.toUpperCase()
|
||||
const exts = ['png', 'pdf', 'jpg', 'jpeg', 'gif', 'doc']
|
||||
const extd = ['ПНГ', 'ПДФ', 'ЖПГ', 'ЖПГ', 'ГИФ', 'ДОК']
|
||||
const units = ['байт', 'КБ', 'МБ', 'ГБ', 'ТБ', 'ПБ']
|
||||
|
||||
export function ext(filname: string): string {
|
||||
const ext = getExt(filname)
|
||||
const i = exts.indexOf(ext)
|
||||
const mime = new Map([
|
||||
['application/pdf', 'ПДФ'],
|
||||
['image/jpeg', 'ЖПГ'],
|
||||
['image/png', 'ПНГ'],
|
||||
])
|
||||
|
||||
return i > -1
|
||||
? extd[i]
|
||||
: defaultExt(ext)
|
||||
export function ext(mimeType: string): string {
|
||||
if (mime.has(mimeType)) {
|
||||
return mime.get(mimeType)
|
||||
}
|
||||
|
||||
return mimeType
|
||||
}
|
||||
|
||||
export function size(bytes: any, precision = 1): string {
|
||||
|
||||
Reference in new issue
Block a user