init nostr
This commit is contained in:
parent
4f94b5fc1f
commit
bec30f2ab0
7 changed files with 1082 additions and 9 deletions
|
|
@ -82,6 +82,7 @@ export class MicroBlogBackend {
|
|||
}
|
||||
|
||||
public async getLatestPostRemoteIDBySource(postSource: MicroBlogPostSource) {
|
||||
await this.checkLogin();
|
||||
const post = await this.getLatestPostBySource(postSource);
|
||||
return post?.remoteId;
|
||||
}
|
||||
|
|
@ -137,6 +138,7 @@ export class MicroBlogBackend {
|
|||
public async savePost(
|
||||
post: Omit<MicroBlogPost, "id" | "expand">
|
||||
): Promise<MicroBlogPost> {
|
||||
await this.checkLogin();
|
||||
const existingPost = await this.checkForPost(post.remoteId);
|
||||
if (!existingPost) {
|
||||
return await this.pb
|
||||
|
|
@ -148,6 +150,7 @@ export class MicroBlogBackend {
|
|||
}
|
||||
|
||||
public async setTag(rawTag: string, postId: string) {
|
||||
await this.checkLogin();
|
||||
let tag = await this.getTag(rawTag);
|
||||
if (!tag) {
|
||||
tag = await this.pb
|
||||
|
|
@ -166,6 +169,7 @@ export class MicroBlogBackend {
|
|||
imageToSave: Omit<MicroBlogPostImage, "id" | "image" | "collectionId">,
|
||||
postId: string
|
||||
) {
|
||||
await this.checkLogin();
|
||||
let image = await this.getImageByRemoteURL(imageToSave.remoteURL);
|
||||
if (!image) {
|
||||
const imageResponse = await fetch(imageToSave.remoteURL);
|
||||
|
|
@ -183,13 +187,15 @@ export class MicroBlogBackend {
|
|||
image = await this.pb
|
||||
.collection<MicroBlogPostTag>("micro_blog_images")
|
||||
.create(data);
|
||||
this.logger.info({ image }, "Created image");
|
||||
}
|
||||
if (!image) {
|
||||
throw new Error("Failed to create image");
|
||||
}
|
||||
await this.pb.collection("micro_blog_posts").update(postId, {
|
||||
const res = await this.pb.collection("micro_blog_posts").update(postId, {
|
||||
"images+": image.id,
|
||||
});
|
||||
this.logger.info({ res }, "Updated post with image");
|
||||
}
|
||||
|
||||
public async getPosts(page: number, limit = 20) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue