OverviewFilesCommitsIssuesDocsReleasesPeers

keet-deobfuscated / @holepunchto / keet-store / store / lib / file.js

31 lines · javascript ref:
import e from "b4a"
import t from "get-mime-type"
export const getMimeType = (e, i = !1) => (e && t(e, i)) || ""
export const isAudioMimeType = (e) => !!e && e.startsWith("audio/")
export const isAudioPath = (e) => isAudioMimeType(getMimeType(e))
export const isAudioVoicePath = (e) => !!e && /^.*\/?recording-[A-Za-z0-9-]+\.m4a$/.test(e)
const i = 10
export const increaseWaveformVolume = (e) => {
  const t = e.reduce((e, t) => Math.max(e, t), 0),
    o = Math.min(1 / t, i)
  return e.map((e) => Math.min(1, e * o))
}
export const base64ToWaveform = (t) => {
  if (!t || "string" != typeof t) return null
  const i = e.from(t, "base64"),
    o = []
  for (let e = 0; e < i.length; e += 1) o.push(i[e] / 255)
  return o
}
export const waveformToBase64 = (t) => {
  const i = new Uint8Array(t.map((e) => Math.round(255 * e)))
  return e.toString(i, "base64")
}
export const isVideoMimeType = (e) => !!e && e.startsWith("video/")
export const isVideoPath = (e) => !!e && isVideoMimeType(getMimeType(e))
const o = { "image/heic": !0, "image/heif": !0, "image/tif": !0, "image/tiff": !0 }
export const isImageMimeType = (e) => !!e && e.startsWith("image/")
export const isMediaMimeType = (e) => isImageMimeType(e) || isVideoMimeType(e)
export const isImagePath = (e) => !!e && isImageMimeType(getMimeType(e))
export const isImageSupportedInDesktop = (e) => !o[e]