This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const now = new Date().getTime(); | |
| const OFFSET_EXPIRE_TIME = 10 * 1000, // 10s | |
| const isExpired = Boolean(expires_at && now - expires_at * 1000 > OFFSET_EXPIRE_TIME); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| export const inRange = (number: number, start: number, end: number): boolean => { | |
| return number >= start && number <= end; | |
| }; | |
| // usage | |
| const ratio = width / height; | |
| const isMatch = inRange(ratio, metadata.min_dimension, metadata.max_ratio); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| export default function () { | |
| const date = new Date(); | |
| const getDay = `0${date.getDate()}`.slice(-2).toString(); | |
| const getMonth = `0${date.getMonth() + 1}`.slice(-2).toString(); | |
| const getYear = date.getFullYear().toString(); | |
| const getHours = `0${date.getHours()}`.slice(-2).toString(); | |
| const getMinutes = `0${date.getMinutes()}`.slice(-2).toString(); | |
| const getSeconds = `0${date.getSeconds()}`.slice(-2).toString(); | |
| return `${getYear}-${getMonth}-${getDay} ${getHours}${getMinutes}${getSeconds}`; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function validateMedia(file) { | |
| // Check file type | |
| const allowedTypes = ['image/jpeg', 'image/png', 'image/gif', 'video/mp4']; | |
| if (!allowedTypes.includes(file.type)) { | |
| throw new Error('Invalid file type. Allowed types are: jpeg, png, gif, mp4'); | |
| } | |
| // Check file size | |
| const maxSize = 10485760; // 10MB in bytes | |
| if (file.size > maxSize) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { FileWithPath } from 'react-dropzone'; | |
| type MetaData = { | |
| type: 'img' | 'video' | 'html'; | |
| sizes: [number, number]; | |
| metadata: { | |
| duration?: number; | |
| }; | |
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function open_file(e) { | |
| var file = e.target.files[0]; | |
| if (!file) { | |
| return; | |
| } | |
| var reader = new FileReader(); | |
| reader.onload = function(e) { | |
| var contents = JSON.parse(e.target.result); | |
| if (contents!=null) { | |
| app.data = Object.assign(app.data,contents) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function download_data(filename, data) { | |
| var blob = new Blob([data], {type: 'application/json'}); | |
| if(window.navigator.msSaveOrOpenBlob) { | |
| window.navigator.msSaveBlob(blob, filename); | |
| } | |
| else{ | |
| var elem = window.document.createElement('a'); | |
| elem.href = window.URL.createObjectURL(blob); | |
| elem.download = filename; | |
| document.body.appendChild(elem); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // input: 20301093 | |
| // output: 20.301.093 | |
| export function numberWithCommas(x:number) { | |
| const separator = "."; | |
| return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, separator); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const socket = new WebSocket(socketUrl); | |
| socket.onopen = (event) => { | |
| console.log('onopen: ', event) | |
| }; | |
| socket.onmessage = (event) => { | |
| console.log('onmessage: ', event.data) | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| export default function (file, delimiter) { | |
| return new Promise((resolve) => { | |
| const fileReader = new FileReader(); | |
| fileReader.readAsText(file); | |
| fileReader.onload = function (event) { | |
| let finalJson = []; | |
| const textData = event.target.result; | |
| let rowArr = textData.split(/\r?\n|\r/) || []; | |
| rowArr = rowArr.filter((row) => row); | |
| const csvHeaders = rowArr[0]?.split(delimiter) || []; |
NewerOlder