Skip to content

Instantly share code, notes, and snippets.

View samuelkarani's full-sized avatar

Samuel Karani Mbaabu samuelkarani

  • University of California, Berkeley
  • Paris, France
View GitHub Profile
const NodeClam = require('clamscan');
module.exports = async function scanFile(filePath) {
console.log(`Attempting virus scan for ${filePath}`);
const clamscan = await new NodeClam().init({
remove_infected: true,
debug_mode: false,
scan_recursively: false,
import * as fileType from 'file-type';
const MIN_FILE_SIZE = 0;
const MAX_FILE_SIZE = Number.MAX_SAFE_INTEGER;
const ALLOWED_FILE_MIMETYPES: string[] = [];
function validateFileSize(file: File): boolean {
return file.size >= MIN_FILE_SIZE && file.size <= MAX_FILE_SIZE;
}
function validateFileMimetype(file: File): Promise<boolean> {
const {
UpdateCounterPartyRisk,
UpdateAssetCounterPartyRisk,
UpdateCounterPartyRiskWithAlerts,
UpdateAssetCounterPartyRiskWithAlerts,
UpdateDDCounterPartyRisk,
UpdateHitStatus,
UpdateBatchStatus,
} = require("@schemas/grid");
const axios = require("axios");
export const getThumbnail = (id, size = 300) =>
`https://drive.google.com/thumbnail?id=${id}&sz=${size}`;
export const getIcon = (mimeType) =>
`https://drive-thirdparty.googleusercontent.com/256/type/${mimeType}`;
export const getFile = (id) => `https://drive.google.com/uc?id=${id}`;
const downloadFile = (id) =>
export function validURL(string) {
const pattern = new RegExp(
"^(https?:\\/\\/)?" + // protocol
"((([a-z\\d]([a-z\\d-]*[a-z\\d])*)\\.)+[a-z]{2,}|" + // domain name
"((\\d{1,3}\\.){3}\\d{1,3}))" + // OR ip (v4) address
"(\\:\\d+)?(\\/[-a-z\\d%_.~+]*)*" + // port and path
"(\\?[;&a-z\\d%_.~+=-]*)?" + // query string
"(\\#[-a-z\\d_]*)?$",
"i"
); // fragment locator
//Original Reference: https://guseyn.com/posts/simple-jwt
function payloadWithExpirationTime (payload, minutesFromNow) {
let date = new Date()
date.setMinutes(date.getMinutes() + minutesFromNow)
payload.exp = date.getTime()
return payload
}