atproto pastebin service: https://plonk.li

rename to plonk.li

+40 -38
+1 -1
lexicons/comment.json
··· 1 { 2 "lexicon": 1, 3 - "id": "ovh.plonk.comment", 4 "defs": { 5 "main": { 6 "type": "record",
··· 1 { 2 "lexicon": 1, 3 + "id": "li.plonk.comment", 4 "defs": { 5 "main": { 6 "type": "record",
+1 -1
lexicons/paste.json
··· 1 { 2 "lexicon": 1, 3 - "id": "ovh.plonk.paste", 4 "defs": { 5 "main": { 6 "type": "record",
··· 1 { 2 "lexicon": 1, 3 + "id": "li.plonk.paste", 4 "defs": { 5 "main": { 6 "type": "record",
+7 -7
src/ingester.ts
··· 2 import { IdResolver } from "@atproto/identity"; 3 import { Firehose } from "@atproto/sync"; 4 import type { Database } from "#/db"; 5 - import * as Paste from "#/lexicons/types/ovh/plonk/paste"; 6 - import * as Comment from "#/lexicons/types/ovh/plonk/comment"; 7 8 export function createIngester(db: Database, idResolver: IdResolver) { 9 const logger = pino({ name: "firehose ingestion" }); ··· 17 18 // If the write is a valid status update 19 if ( 20 - evt.collection === "ovh.plonk.paste" && 21 Paste.isRecord(record) && 22 Paste.validateRecord(record).success 23 ) { ··· 43 ) 44 .execute(); 45 } else if ( 46 - evt.collection === "ovh.plonk.comment" && 47 Comment.isRecord(record) && 48 Comment.validateRecord(record).success 49 ) { ··· 70 } 71 } else if ( 72 evt.event === "delete" && 73 - evt.collection === "ovh.plonk.paste" 74 ) { 75 // Remove the status from our SQLite 76 await db ··· 79 .execute(); 80 } else if ( 81 evt.event === "delete" && 82 - evt.collection === "ovh.plonk.comment" 83 ) { 84 // Remove the status from our SQLite 85 await db ··· 91 onError: (err) => { 92 logger.error({ err }, "error on firehose ingestion"); 93 }, 94 - filterCollections: ["ovh.plonk.paste"], 95 excludeIdentity: true, 96 excludeAccount: true, 97 });
··· 2 import { IdResolver } from "@atproto/identity"; 3 import { Firehose } from "@atproto/sync"; 4 import type { Database } from "#/db"; 5 + import * as Paste from "#/lexicons/types/li/plonk/paste"; 6 + import * as Comment from "#/lexicons/types/li/plonk/comment"; 7 8 export function createIngester(db: Database, idResolver: IdResolver) { 9 const logger = pino({ name: "firehose ingestion" }); ··· 17 18 // If the write is a valid status update 19 if ( 20 + evt.collection === "li.plonk.paste" && 21 Paste.isRecord(record) && 22 Paste.validateRecord(record).success 23 ) { ··· 43 ) 44 .execute(); 45 } else if ( 46 + evt.collection === "li.plonk.comment" && 47 Comment.isRecord(record) && 48 Comment.validateRecord(record).success 49 ) { ··· 70 } 71 } else if ( 72 evt.event === "delete" && 73 + evt.collection === "li.plonk.paste" 74 ) { 75 // Remove the status from our SQLite 76 await db ··· 79 .execute(); 80 } else if ( 81 evt.event === "delete" && 82 + evt.collection === "li.plonk.comment" 83 ) { 84 // Remove the status from our SQLite 85 await db ··· 91 onError: (err) => { 92 logger.error({ err }, "error on firehose ingestion"); 93 }, 94 + filterCollections: ["li.plonk.paste"], 95 excludeIdentity: true, 96 excludeAccount: true, 97 });
+6 -6
src/lexicons/index.ts
··· 18 19 export class Server { 20 xrpc: XrpcServer 21 - ovh: OvhNS 22 com: ComNS 23 app: AppNS 24 25 constructor(options?: XrpcOptions) { 26 this.xrpc = createXrpcServer(schemas, options) 27 - this.ovh = new OvhNS(this) 28 this.com = new ComNS(this) 29 this.app = new AppNS(this) 30 } 31 } 32 33 - export class OvhNS { 34 _server: Server 35 - plonk: OvhPlonkNS 36 37 constructor(server: Server) { 38 this._server = server 39 - this.plonk = new OvhPlonkNS(server) 40 } 41 } 42 43 - export class OvhPlonkNS { 44 _server: Server 45 46 constructor(server: Server) {
··· 18 19 export class Server { 20 xrpc: XrpcServer 21 + li: LiNS 22 com: ComNS 23 app: AppNS 24 25 constructor(options?: XrpcOptions) { 26 this.xrpc = createXrpcServer(schemas, options) 27 + this.li = new LiNS(this) 28 this.com = new ComNS(this) 29 this.app = new AppNS(this) 30 } 31 } 32 33 + export class LiNS { 34 _server: Server 35 + plonk: LiPlonkNS 36 37 constructor(server: Server) { 38 this._server = server 39 + this.plonk = new LiPlonkNS(server) 40 } 41 } 42 43 + export class LiPlonkNS { 44 _server: Server 45 46 constructor(server: Server) {
+6 -6
src/lexicons/lexicons.ts
··· 4 import { LexiconDoc, Lexicons } from '@atproto/lexicon' 5 6 export const schemaDict = { 7 - OvhPlonkComment: { 8 lexicon: 1, 9 - id: 'ovh.plonk.comment', 10 defs: { 11 main: { 12 type: 'record', ··· 363 }, 364 }, 365 }, 366 - OvhPlonkPaste: { 367 lexicon: 1, 368 - id: 'ovh.plonk.paste', 369 defs: { 370 main: { 371 type: 'record', ··· 487 export const schemas: LexiconDoc[] = Object.values(schemaDict) as LexiconDoc[] 488 export const lexicons: Lexicons = new Lexicons(schemas) 489 export const ids = { 490 - OvhPlonkComment: 'ovh.plonk.comment', 491 ComAtprotoLabelDefs: 'com.atproto.label.defs', 492 ComAtprotoRepoGetRecord: 'com.atproto.repo.getRecord', 493 ComAtprotoRepoListRecords: 'com.atproto.repo.listRecords', 494 - OvhPlonkPaste: 'ovh.plonk.paste', 495 AppBskyActorProfile: 'app.bsky.actor.profile', 496 ComAtprotoRepoStrongRef: 'com.atproto.repo.strongRef', 497 }
··· 4 import { LexiconDoc, Lexicons } from '@atproto/lexicon' 5 6 export const schemaDict = { 7 + LiPlonkComment: { 8 lexicon: 1, 9 + id: 'li.plonk.comment', 10 defs: { 11 main: { 12 type: 'record', ··· 363 }, 364 }, 365 }, 366 + LiPlonkPaste: { 367 lexicon: 1, 368 + id: 'li.plonk.paste', 369 defs: { 370 main: { 371 type: 'record', ··· 487 export const schemas: LexiconDoc[] = Object.values(schemaDict) as LexiconDoc[] 488 export const lexicons: Lexicons = new Lexicons(schemas) 489 export const ids = { 490 + LiPlonkComment: 'li.plonk.comment', 491 ComAtprotoLabelDefs: 'com.atproto.label.defs', 492 ComAtprotoRepoGetRecord: 'com.atproto.repo.getRecord', 493 ComAtprotoRepoListRecords: 'com.atproto.repo.listRecords', 494 + LiPlonkPaste: 'li.plonk.paste', 495 AppBskyActorProfile: 'app.bsky.actor.profile', 496 ComAtprotoRepoStrongRef: 'com.atproto.repo.strongRef', 497 }
+2 -2
src/lexicons/types/ovh/plonk/comment.ts src/lexicons/types/li/plonk/comment.ts
··· 20 return ( 21 isObj(v) && 22 hasProp(v, '$type') && 23 - (v.$type === 'ovh.plonk.comment#main' || v.$type === 'ovh.plonk.comment') 24 ) 25 } 26 27 export function validateRecord(v: unknown): ValidationResult { 28 - return lexicons.validate('ovh.plonk.comment#main', v) 29 }
··· 20 return ( 21 isObj(v) && 22 hasProp(v, '$type') && 23 + (v.$type === 'li.plonk.comment#main' || v.$type === 'li.plonk.comment') 24 ) 25 } 26 27 export function validateRecord(v: unknown): ValidationResult { 28 + return lexicons.validate('li.plonk.comment#main', v) 29 }
+2 -2
src/lexicons/types/ovh/plonk/paste.ts src/lexicons/types/li/plonk/paste.ts
··· 19 return ( 20 isObj(v) && 21 hasProp(v, '$type') && 22 - (v.$type === 'ovh.plonk.paste#main' || v.$type === 'ovh.plonk.paste') 23 ) 24 } 25 26 export function validateRecord(v: unknown): ValidationResult { 27 - return lexicons.validate('ovh.plonk.paste#main', v) 28 }
··· 19 return ( 20 isObj(v) && 21 hasProp(v, '$type') && 22 + (v.$type === 'li.plonk.paste#main' || v.$type === 'li.plonk.paste') 23 ) 24 } 25 26 export function validateRecord(v: unknown): ValidationResult { 27 + return lexicons.validate('li.plonk.paste#main', v) 28 }
+7
src/public/styles.css
··· 147 justify-content: space-between; 148 align-items: center; 149 }
··· 147 justify-content: space-between; 148 align-items: center; 149 } 150 + 151 + select { 152 + -webkit-appearance: none; 153 + -moz-appearance: none; 154 + text-indent: 1px; 155 + text-overflow: ''; 156 + }
+8 -13
src/routes.ts
··· 11 import { Agent } from "@atproto/api"; 12 import { newShortUrl } from "#/db"; 13 14 - import * as Paste from "#/lexicons/types/ovh/plonk/paste"; 15 - import * as Comment from "#/lexicons/types/ovh/plonk/comment"; 16 import { ComAtprotoRepoNS } from "#/lexicons"; 17 18 type Session = { ··· 145 const agent = new Agent(pds); 146 const response = await agent.com.atproto.repo.listRecords({ 147 repo: authorDid, 148 - collection: 'ovh.plonk.paste', 149 limit: 99, 150 }); 151 const pastes = response.data.records; ··· 224 } 225 const response = await agent.com.atproto.repo.listRecords({ 226 repo: agent.assertDid, 227 - collection: 'ovh.plonk.paste', 228 limit: 10, 229 }); 230 const vals = response.data.records; ··· 251 const rkey = TID.nextStr(); 252 const shortUrl = await newShortUrl(ctx.db); 253 const record = { 254 - $type: "ovh.plonk.paste", 255 code: req.body?.code, 256 lang: req.body?.lang, 257 shortUrl, ··· 270 try { 271 const res = await agent.com.atproto.repo.putRecord({ 272 repo: agent.assertDid, 273 - collection: "ovh.plonk.paste", 274 rkey, 275 record, 276 validate: false, ··· 299 indexedAt: new Date().toISOString(), 300 }) 301 .execute(); 302 - ctx.logger.info(res, "wrote back to db"); 303 return res.redirect(`/p/${shortUrl}`); 304 } catch (err) { 305 ctx.logger.warn( ··· 338 339 const rkey = TID.nextStr(); 340 const record = { 341 - $type: "ovh.plonk.comment", 342 content: req.body?.comment, 343 post: { 344 uri: pasteUri, ··· 358 try { 359 const res = await agent.com.atproto.repo.putRecord({ 360 repo: agent.assertDid, 361 - collection: "ovh.plonk.comment", 362 rkey, 363 record, 364 validate: false, ··· 400 401 return router; 402 }; 403 - 404 - // https://pds.icyphox.sh/xrpc/com.atproto.repo.getRecord?repo=did%3Aplc%3A3ft67n4xnawzq4qi7mcksxj5 405 - // at://did:plc:3ft67n4xnawzq4qi7mcksxj5/ovh.plonk.paste/3lcs3lnslbk2d 406 - // https://pds.icyphox.sh/xrpc/com.atproto.repo.getRecord?repo=did%3Aplc%3A3ft67n4xnawzq4qi7mcksxj5&collection=ovh.plonk.paste&rkey=3lcqt7newvc2c
··· 11 import { Agent } from "@atproto/api"; 12 import { newShortUrl } from "#/db"; 13 14 + import * as Paste from "#/lexicons/types/li/plonk/paste"; 15 + import * as Comment from "#/lexicons/types/li/plonk/comment"; 16 import { ComAtprotoRepoNS } from "#/lexicons"; 17 18 type Session = { ··· 145 const agent = new Agent(pds); 146 const response = await agent.com.atproto.repo.listRecords({ 147 repo: authorDid, 148 + collection: 'li.plonk.paste', 149 limit: 99, 150 }); 151 const pastes = response.data.records; ··· 224 } 225 const response = await agent.com.atproto.repo.listRecords({ 226 repo: agent.assertDid, 227 + collection: 'li.plonk.paste', 228 limit: 10, 229 }); 230 const vals = response.data.records; ··· 251 const rkey = TID.nextStr(); 252 const shortUrl = await newShortUrl(ctx.db); 253 const record = { 254 + $type: "li.plonk.paste", 255 code: req.body?.code, 256 lang: req.body?.lang, 257 shortUrl, ··· 270 try { 271 const res = await agent.com.atproto.repo.putRecord({ 272 repo: agent.assertDid, 273 + collection: "li.plonk.paste", 274 rkey, 275 record, 276 validate: false, ··· 299 indexedAt: new Date().toISOString(), 300 }) 301 .execute(); 302 return res.redirect(`/p/${shortUrl}`); 303 } catch (err) { 304 ctx.logger.warn( ··· 337 338 const rkey = TID.nextStr(); 339 const record = { 340 + $type: "li.plonk.comment", 341 content: req.body?.comment, 342 post: { 343 uri: pasteUri, ··· 357 try { 358 const res = await agent.com.atproto.repo.putRecord({ 359 repo: agent.assertDid, 360 + collection: "li.plonk.comment", 361 rkey, 362 record, 363 validate: false, ··· 399 400 return router; 401 };