diff --git a/appview/index.ts b/appview/index.ts index 4c537dd6..269f1309 100644 --- a/appview/index.ts +++ b/appview/index.ts @@ -104,25 +104,28 @@ async function handleEvent(evt: Event) { data: record.value as Json, }); if (docResult.error) console.log(docResult.error); - let publicationURI = new AtUri(record.value.publication); + if (record.value.publication) { + let publicationURI = new AtUri(record.value.publication); - if (publicationURI.host !== evt.uri.host) { - console.log("Unauthorized to create post!"); - return; + if (publicationURI.host !== evt.uri.host) { + console.log("Unauthorized to create post!"); + return; + } + let docInPublicationResult = await supabase + .from("documents_in_publications") + .upsert({ + publication: record.value.publication, + document: evt.uri.toString(), + }); + await supabase + .from("documents_in_publications") + .delete() + .neq("publication", record.value.publication) + .eq("document", evt.uri.toString()); + + if (docInPublicationResult.error) + console.log(docInPublicationResult.error); } - let docInPublicationResult = await supabase - .from("documents_in_publications") - .upsert({ - publication: record.value.publication, - document: evt.uri.toString(), - }); - await supabase - .from("documents_in_publications") - .delete() - .neq("publication", record.value.publication) - .eq("document", evt.uri.toString()); - if (docInPublicationResult.error) - console.log(docInPublicationResult.error); } if (evt.event === "delete") { await supabase.from("documents").delete().eq("uri", evt.uri.toString()); diff --git a/lexicons/api/lexicons.ts b/lexicons/api/lexicons.ts index dcf8539c..35d90268 100644 --- a/lexicons/api/lexicons.ts +++ b/lexicons/api/lexicons.ts @@ -1408,7 +1408,7 @@ export const schemaDict = { description: 'Record containing a document', record: { type: 'object', - required: ['pages', 'author', 'title', 'publication'], + required: ['pages', 'author', 'title'], properties: { title: { type: 'string', diff --git a/lexicons/api/types/pub/leaflet/document.ts b/lexicons/api/types/pub/leaflet/document.ts index cf3a930d..066fe693 100644 --- a/lexicons/api/types/pub/leaflet/document.ts +++ b/lexicons/api/types/pub/leaflet/document.ts @@ -19,7 +19,7 @@ export interface Record { postRef?: ComAtprotoRepoStrongRef.Main description?: string publishedAt?: string - publication: string + publication?: string author: string pages: ( | $Typed diff --git a/lexicons/pub/leaflet/document.json b/lexicons/pub/leaflet/document.json index 9e8082bd..005bbd39 100644 --- a/lexicons/pub/leaflet/document.json +++ b/lexicons/pub/leaflet/document.json @@ -13,8 +13,7 @@ "required": [ "pages", "author", - "title", - "publication" + "title" ], "properties": { "title": { diff --git a/lexicons/src/document.ts b/lexicons/src/document.ts index 1530428c..7484ad34 100644 --- a/lexicons/src/document.ts +++ b/lexicons/src/document.ts @@ -14,7 +14,7 @@ export const PubLeafletDocument: LexiconDoc = { description: "Record containing a document", record: { type: "object", - required: ["pages", "author", "title", "publication"], + required: ["pages", "author", "title"], properties: { title: { type: "string", maxLength: 1280, maxGraphemes: 128 }, postRef: { type: "ref", ref: "com.atproto.repo.strongRef" },