Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
Commit
β’
b3e635b
1
Parent(s):
cdb6f86
fix for the future community feature
Browse files- src/app/engine/community.ts +6 -3
- src/types.ts +6 -0
src/app/engine/community.ts
CHANGED
@@ -2,7 +2,7 @@
|
|
2 |
|
3 |
import { v4 as uuidv4 } from "uuid"
|
4 |
|
5 |
-
import { CreatePostResponse, GetAppPostsResponse, Post } from "@/types"
|
6 |
|
7 |
const apiUrl = `${process.env.COMMUNITY_API_URL || ""}`
|
8 |
const apiToken = `${process.env.COMMUNITY_API_TOKEN || ""}`
|
@@ -25,6 +25,7 @@ export async function postToCommunity({
|
|
25 |
previewUrl: assetUrl,
|
26 |
assetUrl,
|
27 |
createdAt: new Date().toISOString(),
|
|
|
28 |
upvotes: 0,
|
29 |
downvotes: 0
|
30 |
}
|
@@ -82,7 +83,7 @@ export async function postToCommunity({
|
|
82 |
}
|
83 |
}
|
84 |
|
85 |
-
export async function getLatestPosts(): Promise<Post[]> {
|
86 |
|
87 |
let posts: Post[] = []
|
88 |
|
@@ -94,7 +95,9 @@ export async function getLatestPosts(): Promise<Post[]> {
|
|
94 |
|
95 |
try {
|
96 |
// console.log(`calling GET ${apiUrl}/posts with renderId: ${renderId}`)
|
97 |
-
const res = await fetch(`${apiUrl}/posts/${appId}
|
|
|
|
|
98 |
method: "GET",
|
99 |
headers: {
|
100 |
Accept: "application/json",
|
|
|
2 |
|
3 |
import { v4 as uuidv4 } from "uuid"
|
4 |
|
5 |
+
import { CreatePostResponse, GetAppPostsResponse, Post, PostVisibility } from "@/types"
|
6 |
|
7 |
const apiUrl = `${process.env.COMMUNITY_API_URL || ""}`
|
8 |
const apiToken = `${process.env.COMMUNITY_API_TOKEN || ""}`
|
|
|
25 |
previewUrl: assetUrl,
|
26 |
assetUrl,
|
27 |
createdAt: new Date().toISOString(),
|
28 |
+
visibility: "normal",
|
29 |
upvotes: 0,
|
30 |
downvotes: 0
|
31 |
}
|
|
|
83 |
}
|
84 |
}
|
85 |
|
86 |
+
export async function getLatestPosts(visibility?: PostVisibility): Promise<Post[]> {
|
87 |
|
88 |
let posts: Post[] = []
|
89 |
|
|
|
95 |
|
96 |
try {
|
97 |
// console.log(`calling GET ${apiUrl}/posts with renderId: ${renderId}`)
|
98 |
+
const res = await fetch(`${apiUrl}/posts/${appId}/${
|
99 |
+
visibility || "all"
|
100 |
+
}`, {
|
101 |
method: "GET",
|
102 |
headers: {
|
103 |
Accept: "application/json",
|
src/types.ts
CHANGED
@@ -92,6 +92,11 @@ export type RenderingEngine =
|
|
92 |
| "OPENAI"
|
93 |
| "REPLICATE"
|
94 |
|
|
|
|
|
|
|
|
|
|
|
95 |
export type Post = {
|
96 |
postId: string
|
97 |
appId: string
|
@@ -99,6 +104,7 @@ export type Post = {
|
|
99 |
previewUrl: string
|
100 |
assetUrl: string
|
101 |
createdAt: string
|
|
|
102 |
upvotes: number
|
103 |
downvotes: number
|
104 |
}
|
|
|
92 |
| "OPENAI"
|
93 |
| "REPLICATE"
|
94 |
|
95 |
+
export type PostVisibility =
|
96 |
+
| "featured" // featured by admins
|
97 |
+
| "trending" // top trending / received more than 10 upvotes
|
98 |
+
| "normal" // default visibility
|
99 |
+
|
100 |
export type Post = {
|
101 |
postId: string
|
102 |
appId: string
|
|
|
104 |
previewUrl: string
|
105 |
assetUrl: string
|
106 |
createdAt: string
|
107 |
+
visibility: PostVisibility
|
108 |
upvotes: number
|
109 |
downvotes: number
|
110 |
}
|