Skip to content

Commit

Permalink
Clean up imports
Browse files Browse the repository at this point in the history
  • Loading branch information
spearcat committed Dec 4, 2024
1 parent c8be079 commit 7ff1254
Showing 1 changed file with 13 additions and 16 deletions.
29 changes: 13 additions & 16 deletions src/utils/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
import { XRPC, XRPCResponse } from "@atcute/client";
import type { At, Brand, ComAtprotoRepoListRecords, IoGithubObsidatGeneric, IoGithubObsidatPublicFile, Records } from "@atcute/client/lexicons";
import { type DuplicationProcessWay, type IMimeTypes, MimeType } from 'mime-type';
import db from 'mime-db';
import { sha256 } from '@noble/hashes/sha256';
import { parse as parseCid, create as createCid, format as formatCid } from '@atcute/cid';
import { blake3 } from "@noble/hashes/blake3";
import { DidDocument } from "@atcute/client/utils/did";
import base32Encode from 'base32-encode';
import base32Decode from 'base32-decode';
import { fromString, toString } from 'uint8arrays';

/*!
The MIT License (MIT)
Expand Down Expand Up @@ -35,7 +44,7 @@ export function toBuffer(arr: ArrayBufferLike) {

export type Awaitable<T> = Awaited<T> | Promise<Awaited<T>>;

interface ListRecordsRecord<K extends keyof Records> {
export interface ListRecordsRecord<K extends keyof Records> {
[Brand.Type]?: 'com.atproto.repo.listRecords#record';
cid: At.CID;
uri: At.Uri;
Expand Down Expand Up @@ -87,26 +96,16 @@ export function truncate(text: string, len = 250) {
return text.slice(0, len - 3) + '...';
}

//create an empty mime-type:
import { type DuplicationProcessWay, type IMimeTypes, MimeType } from 'mime-type';
import db from 'mime-db';
const mime = new MimeType(db as IMimeTypes, 0 as DuplicationProcessWay);

let mime: MimeType | undefined;
export function detectMimeType(pathOrExtension: string) {
mime ??= new MimeType(db as IMimeTypes, 0 as DuplicationProcessWay);

let result = mime.lookup(pathOrExtension);
if (!result) return 'application/octet-stream';
if (Array.isArray(result)) result = result[0];
return result;
}

import { sha256 } from '@noble/hashes/sha256';
import { parse as parseCid, create as createCid, format as formatCid } from '@atcute/cid';
import { CrockfordBase32 } from "crockford-base32";
import { blake3 } from "@noble/hashes/blake3";
import { DidDocument } from "@atcute/client/utils/did";
import base32Encode from 'base32-encode';
import base32Decode from 'base32-decode';

export function isCidMatching(data: ArrayBufferLike, blob: At.Blob) {
const cid = parseCid(blob.ref.$link);
const digest = cid.digest.digest;
Expand Down Expand Up @@ -211,8 +210,6 @@ export function getHandle(didDoc: DidDocument) {
?.slice('at://'.length);
}

import { fromString, toString } from 'uint8arrays';

export function arrayBufferToBase64(arrayBuffer: ArrayBufferLike) {
return toString(new Uint8Array(arrayBuffer), 'base64');
}
Expand Down

0 comments on commit 7ff1254

Please sign in to comment.