Compare commits
7 commits
cc3afe1eaa
...
3543529600
Author | SHA1 | Date | |
---|---|---|---|
3543529600 | |||
00c9a3686e | |||
6748d01158 | |||
6333b0801c | |||
b11cb3e5b6 | |||
31599d488e | |||
a6e9198e86 |
1 changed files with 19 additions and 16 deletions
35
main.ts
35
main.ts
|
@ -54,7 +54,7 @@ const relay = new NRelay1(relay_str);
|
||||||
|
|
||||||
console.log("\nAs a sanity check, here's your last message (if any):");
|
console.log("\nAs a sanity check, here's your last message (if any):");
|
||||||
|
|
||||||
for await (const msg of relay.req([{ kinds: [1], limit: 960, authors: [pubkey_hex] }])) {
|
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] === 'EVENT') console.log(msg[2].content);
|
||||||
if (msg[0] === 'EOSE') break;
|
if (msg[0] === 'EOSE') break;
|
||||||
}
|
}
|
||||||
|
@ -92,6 +92,7 @@ for (const i in posts) {
|
||||||
|
|
||||||
// Populated from the first media item with coordinates
|
// Populated from the first media item with coordinates
|
||||||
let geotags;
|
let geotags;
|
||||||
|
let event_tags: string[][] = [];
|
||||||
|
|
||||||
let first = true;
|
let first = true;
|
||||||
for (const j in post.media) {
|
for (const j in post.media) {
|
||||||
|
@ -139,23 +140,27 @@ for (const i in posts) {
|
||||||
|
|
||||||
if (geotags == undefined && media.media_metadata && media.media_metadata.photo_metadata) {
|
if (geotags == undefined && media.media_metadata && media.media_metadata.photo_metadata) {
|
||||||
const options = {
|
const options = {
|
||||||
geohash: true,
|
geohash: true, // l tag per NIP-52, adds multiple tags at decreasing resolution
|
||||||
gps: true,
|
gps: false, // Avoid multiple tags, insert them manually below.
|
||||||
city: false,
|
city: false,
|
||||||
iso31662: false,
|
iso31662: false,
|
||||||
iso31662: false,
|
|
||||||
iso31663: false
|
iso31663: false
|
||||||
};
|
};
|
||||||
|
|
||||||
let exif_data = media.media_metadata.photo_metadata.exif_data;
|
const exif_data = media.media_metadata.photo_metadata.exif_data;
|
||||||
if (exif_data) {
|
if (exif_data) {
|
||||||
for (const k in exif_data) {
|
for (const k in exif_data) {
|
||||||
const exif_item = exif_data[k];
|
const exif_item = exif_data[k];
|
||||||
if (exif_item.latitude != undefined && exif_item.latitude != undefined) {
|
if (exif_item.latitude != undefined && exif_item.latitude != undefined) {
|
||||||
geotags = ngeotags({
|
// Add coordinates as a tag.
|
||||||
|
// There is currently no NIP defining a wgs84 tag!
|
||||||
|
event_tags.push(['wgs84', String(exif_item.latitude), String(exif_item.longitude)])
|
||||||
|
// Encode coordinates as Geohash in different resolutions:
|
||||||
|
// https://en.wikipedia.org/wiki/Geohash
|
||||||
|
event_tags = [...event_tags, ...ngeotags({
|
||||||
lat: exif_item.latitude,
|
lat: exif_item.latitude,
|
||||||
lon: exif_item.longitude
|
lon: exif_item.longitude
|
||||||
}, options);
|
}, options)];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -166,15 +171,12 @@ for (const i in posts) {
|
||||||
let event = {
|
let event = {
|
||||||
kind: 1,
|
kind: 1,
|
||||||
content: message,
|
content: message,
|
||||||
tags: [],
|
tags: event_tags,
|
||||||
created_at: created_at
|
created_at: created_at
|
||||||
}
|
}
|
||||||
if (geotags != undefined) {
|
|
||||||
event.tags = [...event.tags, ...geotags];
|
|
||||||
}
|
|
||||||
const signed_event = await signer.signEvent(event);
|
const signed_event = await signer.signEvent(event);
|
||||||
console.log(event);
|
console.log(signed_event);
|
||||||
events.push(event);
|
events.push(signed_event);
|
||||||
|
|
||||||
completed++;
|
completed++;
|
||||||
if (completed == n) break;
|
if (completed == n) break;
|
||||||
|
@ -182,9 +184,10 @@ for (const i in posts) {
|
||||||
|
|
||||||
alert("About to post to Nostr.");
|
alert("About to post to Nostr.");
|
||||||
|
|
||||||
for (const event in events) {
|
for (const i in events) {
|
||||||
console.log(event);
|
const event = events[i]
|
||||||
console.log(await relay.event(event));
|
await relay.event(event);
|
||||||
|
console.log(event.id);
|
||||||
}
|
}
|
||||||
|
|
||||||
await relay.close()
|
await relay.close()
|
||||||
|
|
Loading…
Reference in a new issue