strip html from description
This commit is contained in:
@@ -13,8 +13,17 @@ const toHexString = nsec => {
|
||||
return s + hex;
|
||||
}, '');
|
||||
}
|
||||
|
||||
|
||||
const htmlToAscii = html => {
|
||||
let ascii = html
|
||||
ascii = ascii.replaceAll("<p>", "")
|
||||
ascii = ascii.replaceAll("</p>", "")
|
||||
ascii = ascii.replaceAll("<br>", "")
|
||||
ascii = ascii.replaceAll("<img src=\"", "")
|
||||
ascii = ascii.replaceAll("\" style=\"max-width:250px;\" />", "")
|
||||
return ascii
|
||||
}
|
||||
|
||||
export const handler = async (event) => {
|
||||
const region = process.env.AWS_REGION || "us-east-1"
|
||||
const feed = event.feedUrl
|
||||
@@ -39,87 +48,88 @@ export const handler = async (event) => {
|
||||
const ssmGetCommand = new GetParameterCommand(params);
|
||||
|
||||
let since = new Date()
|
||||
ssmClient.send(ssmGetCommand)
|
||||
await ssmClient.send(ssmGetCommand)
|
||||
.then(data => {
|
||||
console.log("Using since date:", data.Parameter.Value)
|
||||
since = data.Parameter.Value
|
||||
}).catch(err => {
|
||||
console.error(err)
|
||||
console.dir(err)
|
||||
response.errors.push(err)
|
||||
return response
|
||||
})
|
||||
|
||||
|
||||
if (feed === "") {
|
||||
console.error("feedUrl was not set.")
|
||||
console.dir("feedUrl was not set.")
|
||||
return {
|
||||
statusCode: 400,
|
||||
body: "feedUrl must be provided in payload."
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
const ndk = new NDK({
|
||||
signer: new NDKPrivateKeySigner(privkey),
|
||||
explicitRelayUrls: [
|
||||
"wss://nostr.mom",
|
||||
"wss://nostr.snort.social",
|
||||
"wss://nostr.lol"
|
||||
]
|
||||
})
|
||||
const user = await ndk.signer.user()
|
||||
|
||||
for (let url of user.relayUrls) {
|
||||
ndk.pool.relays.push(url)
|
||||
}
|
||||
|
||||
await ndk.connect(6000).catch(err => {
|
||||
console.error(err)
|
||||
response.errors.push ("failed to connect to relay", err)
|
||||
console.dir(err)
|
||||
response.errors.push("failed to connect to relay", err)
|
||||
})
|
||||
|
||||
let rss = await extract(feed)
|
||||
const signer = new NDKPrivateKeySigner(privkey)
|
||||
ndk.signer = signer
|
||||
|
||||
let rss = await extract(feed, { descriptionMaxLen: 0, normalization: false })
|
||||
.catch(err => {
|
||||
console.error(err.error);
|
||||
console.dir(err);
|
||||
return response
|
||||
})
|
||||
|
||||
let filtered = rss.entries.filter(item => moment(item.published).isAfter(since))
|
||||
let filtered = rss.item.filter(item => moment(item.published).isAfter(since))
|
||||
response.totalItems = filtered.length
|
||||
|
||||
for (let item of filtered) {
|
||||
let ndkEvent = new NDKEvent(ndk, {
|
||||
kind: 1,
|
||||
pubkey: user.hexpubkey,
|
||||
content: `${item.description}\n${item.link}`,
|
||||
pubkey: ndk.signer.user().hexpubkey,
|
||||
content: htmlToAscii(item.description),
|
||||
created_at: Math.floor(Date.now() / 1000),
|
||||
})
|
||||
|
||||
if (dryrun) {
|
||||
console.dir(ndkEvent)
|
||||
response.successes++
|
||||
continue
|
||||
}
|
||||
|
||||
await ndkEvent.publish()
|
||||
.then(() => {
|
||||
try {
|
||||
await ndkEvent.sign(ndk.signer)
|
||||
const published = await ndkEvent.publish()
|
||||
if (published) {
|
||||
response.successes++
|
||||
}).catch(err => {
|
||||
console.error(err)
|
||||
response.errors.push(err)
|
||||
})
|
||||
}
|
||||
|
||||
params.Name = lastRunTimeParam
|
||||
params.Value = new Date().toISOString()
|
||||
params.Type = "String"
|
||||
params.Overwrite = true
|
||||
|
||||
params.Name = lastRunTimeParam
|
||||
params.Value = new Date().toISOString()
|
||||
params.Type = "String"
|
||||
params.Overwrite = true
|
||||
|
||||
const ssmPutCommand = new PutParameterCommand(params)
|
||||
ssmClient.send(ssmPutCommand)
|
||||
.catch(err => {
|
||||
console.error(err)
|
||||
response.errors.push(err)
|
||||
const ssmPutCommand = new PutParameterCommand(params)
|
||||
await ssmClient.send(ssmPutCommand)
|
||||
.catch(err => {
|
||||
console.dir(err)
|
||||
response.errors.push(err)
|
||||
return response
|
||||
})
|
||||
}
|
||||
} catch(e) {
|
||||
console.dir(e)
|
||||
response.errors.push(e)
|
||||
return response
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
return response
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user