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