1
0
Fork 0
instablossom/main.ts

56 lines
1.6 KiB
TypeScript
Raw Normal View History

import { assert } from "https://deno.land/std@0.224.0/assert/mod.ts";
import {
NSchema,
NSecSigner,
NRelay1
} from '@nostrify/nostrify';
import * as nip19 from 'nostr-tools/nip19'
console.log("\nUse at your own risk!\n");
console.log("Considering trying it out with a throwaway nsec.");
console.log("All data will be public. Anything you upload is hard to delete.\n");
2024-08-31 17:29:32 +00:00
const path = prompt("Enter Instagram backup (absolute) path (unzip first): ");
const posts = JSON.parse(await Deno.readTextFile(path + "/content/posts_1.json"));
console.log("Number of posts:", posts.length);
console.log("You can try one picture at a time, duplicates are skipped the next run.");
const n = Number(prompt("How many do you want to upload?", posts.length));
if (n == 0) { Deno.exit(0); }
assert(n > 0);
assert(n <= posts.length);
const nsec_str = prompt("\nPlease enter your nsec:");
// Sanity check format
NSchema.bech32('nsec').parse(nsec_str);
// Actually parse nsec
const { type, data } = nip19.decode(nsec_str);
assert(type === 'nsec');
const signer = new NSecSigner(data);
const pubkey_hex = await signer.getPublicKey();
const npub = nip19.npubEncode(pubkey_hex);
console.log("\nYour npub: ", npub);
console.log("In hex format: ", pubkey_hex);
// TODO: get relays from profile and/or allow multiple
const relay_str = prompt("Pick a relay:");
const relay = new NRelay1(relay_str);
console.log("\nAs a sanity check, here's your last message (if any):");
for await (const msg of relay.req([{ kinds: [1], limit: 1, authors: [pubkey_hex] }])) {
if (msg[0] === 'EVENT') console.log(msg[2].content);
if (msg[0] === 'EOSE') break;
}
await relay.close()