···9191 // Store the new/updated record in the repo.
9292 api.putFeedGeneratorRecord(repo, rkey, feedGeneratorRecord)
9393}
9494-9595-//@Serializable
9696-//data class DidDoc(
9797-// val id: String,
9898-// val service: List<Service>,
9999-//) {
100100-// @Serializable
101101-// data class Service(
102102-// val id: String,
103103-// val type: String,
104104-// val serviceEndpoint: String,
105105-// )
106106-//}
107107-//
108108-//@Serializable
109109-//data class FeedSkeleton(
110110-// val cursor: String? = null,
111111-// val feed: List<FeedObject>,
112112-//) {
113113-// @Serializable
114114-// data class FeedObject(
115115-// val post: String,
116116-// val reason: ReasonRepost? = null,
117117-// val feedContext: String? = null,
118118-// ) {
119119-// @Serializable
120120-// data class ReasonRepost(
121121-// val repost: String,
122122-// )
123123-// }
124124-//}
125125-//
126126-//@Serializable
127127-//data class AppBskyFeedGenerator(
128128-// val did: String,
129129-// @SerialName("\$type")
130130-// val type: String? = null,
131131-// val displayName: String? = null,
132132-// val createdAt: String? = null,
133133-//)
134134-//
135135-//fun main() {
136136-// val hostname = ""
137137-// val ownerPds = ""
138138-// val ownerDid = ""
139139-// val ownerAppPassword = ""
140140-// val feedRecordKey = ""
141141-//
142142-// val client = HttpClient(CIO) {
143143-// install(io.ktor.client.plugins.contentnegotiation.ContentNegotiation) {
144144-// json(
145145-// Json {
146146-// explicitNulls = false
147147-// ignoreUnknownKeys = true
148148-// }
149149-// )
150150-// }
151151-// }
152152-//
153153-// runBlocking {
154154-// val getRecordResponse = client.get("https://$ownerPds/xrpc/com.atproto.repo.getRecord") {
155155-// url {
156156-// parameters.append("repo", ownerDid)
157157-// parameters.append("collection", "app.bsky.feed.generator")
158158-// parameters.append("rkey", feedRecordKey)
159159-// }
160160-// }
161161-//
162162-// @Serializable
163163-// data class GetRecordResponse(
164164-// val uri: String,
165165-// val cid: String?,
166166-// val value: AppBskyFeedGenerator,
167167-// )
168168-//
169169-//// val appBskyFeedGeneratorRecord: GetRecordResponse = getRecordResponse.body()
170170-//
171171-// val appBskyFeedGeneratorRecord: GetRecordResponse? = if (getRecordResponse.status == HttpStatusCode.OK) {
172172-// getRecordResponse.body()
173173-// } else {
174174-// null
175175-// }
176176-//
177177-// if (appBskyFeedGeneratorRecord?.value?.did?.contains(hostname) == true) {
178178-// return@runBlocking
179179-// }
180180-//
181181-// println("Updating app.bsky.feed.record did with new hostname $hostname")
182182-//
183183-// @Serializable
184184-// data class CreateSessionRequest(
185185-// val identifier: String,
186186-// val password: String,
187187-// )
188188-//
189189-// @Serializable
190190-// data class CreateSessionResponse(
191191-// val accessJwt: String,
192192-// val refreshJwt: String,
193193-// val did: String,
194194-// )
195195-//
196196-// val sessionTokens: CreateSessionResponse =
197197-// client.post("https://$ownerPds/xrpc/com.atproto.server.createSession") {
198198-// contentType(ContentType.Application.Json)
199199-// setBody(
200200-// CreateSessionRequest(
201201-// identifier = ownerDid,
202202-// password = ownerAppPassword,
203203-// )
204204-// )
205205-// }.body()
206206-//
207207-//
208208-// if (sessionTokens.did != ownerDid) {
209209-// println("How is this possible!? :O")
210210-// return@runBlocking
211211-// }
212212-//
213213-// @Serializable
214214-// data class PutRecordRequest(
215215-// val repo: String,
216216-// val collection: String,
217217-// val rkey: String,
218218-// val validate: Boolean? = null,
219219-// val record: AppBskyFeedGenerator,
220220-// val swapRecord: String? = null,
221221-// val swapCommit: String? = null,
222222-// )
223223-//
224224-// val putRecordResponse = client.post("https://$ownerPds/xrpc/com.atproto.repo.putRecord") {
225225-// header("Authorization", "Bearer ${sessionTokens.accessJwt}")
226226-// contentType(ContentType.Application.Json)
227227-// setBody(
228228-// PutRecordRequest(
229229-// repo = ownerDid,
230230-// collection = "app.bsky.feed.generator",
231231-// rkey = feedRecordKey,
232232-// record = AppBskyFeedGenerator(
233233-// did = "did:web:$hostname",
234234-// displayName = "DarkFeed",
235235-// createdAt = "2024-11-04T15:58:05.074Z",
236236-// )
237237-// )
238238-// )
239239-// }
240240-//
241241-// if (putRecordResponse.status != HttpStatusCode.OK) {
242242-// println("Failed to update hostname in feed generator record: ${putRecordResponse.bodyAsText()}")
243243-// }
244244-// }
245245-//
246246-// // Run DarkFeed server.
247247-// embeddedServer(Netty, port = 8080) {
248248-// install(ContentNegotiation) {
249249-// json(Json { explicitNulls = false })
250250-// }
251251-//
252252-// routing {
253253-// get("/.well-known/did.json") {
254254-// call.respond(
255255-// DidDoc(
256256-// id = "did:web:$hostname",
257257-// service = listOf(
258258-// DidDoc.Service(
259259-// id = "#bsky_fg",
260260-// type = "BskyFeedGenerator",
261261-// serviceEndpoint = "https://$hostname",
262262-// )
263263-// )
264264-// )
265265-// )
266266-// }
267267-//
268268-// get("/xrpc/app.bsky.feed.getFeedSkeleton") {
269269-// call.respond(buildFeedSkeleton(actor = ownerDid))
270270-// }
271271-// }
272272-// }.start(wait = true)
273273-//}
274274-//
275275-//// SOOOOO
276276-//// I NEED TO CHECK THE SELF LABEL (at://did:plc:vwivwqztbf6pmkgss3nv2scy/app.bsky.feed.post/3la5sxh4ica2r)
277277-//// AND THE MODERATION.BSKY.APP LABEL (at://did:plc:ujrpupcjf22a4riwjbupdv42/app.bsky.feed.post/3la5qntezsu2v)
278278-//suspend fun buildFeedSkeleton(actor: String) = FeedSkeleton(
279279-// feed = getActorLikes(actor = actor)
280280-// .map { FeedSkeleton.FeedObject(post = it) }
281281-//)
282282-//
283283-//suspend fun getPostLabels(uris: List<String>): Unit {
284284-// val client = HttpClient(CIO) {
285285-// install(io.ktor.client.plugins.contentnegotiation.ContentNegotiation) {
286286-// json(
287287-// Json {
288288-// explicitNulls = false
289289-// ignoreUnknownKeys = true
290290-// }
291291-// )
292292-// }
293293-// }
294294-//
295295-// @Serializable
296296-// data class GetPostsRequest(
297297-// val uris: List<String>,
298298-// )
299299-//
300300-// @Serializable
301301-// data class Label(
302302-// val ver: Int,
303303-// val src: String,
304304-// val uri: String,
305305-// val cid: String,
306306-// @SerialName("val")
307307-// val _val: String,
308308-// val cts: String,
309309-// )
310310-//
311311-// @Serializable
312312-// data class HydratedPostView(
313313-// val uri: String,
314314-// val cid: String,
315315-// val labels: List<Label>,
316316-// )
317317-//
318318-// @Serializable
319319-// data class GetPostsResponse(
320320-// val posts: List<HydratedPostView>,
321321-// )
322322-//
323323-// val getPostsResponse = client.get("https://bsky.social/xrpc/app.bsky.geed.getPosts") {
324324-// parameters {
325325-// uris.forEach { uri -> parameter("uris", uri) }
326326-// }
327327-// }
328328-//
329329-// println(getPostsResponse.bodyAsText())
330330-//
331331-// val posts: GetPostsResponse = getPostsResponse.body()
332332-//
333333-// println(getPostsResponse)
334334-//}
335335-//
336336-//suspend fun getActorLikes(actor: String, cursor: String? = null): List<String> {
337337-// val client = HttpClient(CIO) {
338338-// install(io.ktor.client.plugins.contentnegotiation.ContentNegotiation) {
339339-// json(
340340-// Json {
341341-// explicitNulls = false
342342-// ignoreUnknownKeys = true
343343-// }
344344-// )
345345-// }
346346-// }
347347-//
348348-// @Serializable
349349-// data class RefRecord(
350350-// val uri: String,
351351-// val cid: String,
352352-// val value: Like,
353353-// )
354354-//
355355-// @Serializable
356356-// data class ListRecordsResponse(
357357-// val cursor: String?,
358358-// val records: List<RefRecord>,
359359-// )
360360-//
361361-// val response = client.get("https://bsky.social/xrpc/com.atproto.repo.listRecords") {
362362-// parameters {
363363-// parameter("repo", actor)
364364-// parameter("collection", "app.bsky.feed.like")
365365-// parameter("limit", 100)
366366-// if (cursor != null) parameter("cursor", cursor)
367367-// }
368368-// }
369369-//
370370-// return response.body<ListRecordsResponse>()
371371-// .records
372372-// .map { it.value.subject.uri }
373373-// .toList()
374374-//}
+4
app/src/main/kotlin/DarkFeedApi.kt
···6868 )
6969 }
70707171+ // SOOOOO
7272+ // I NEED TO CHECK THE SELF LABEL (at://did:plc:vwivwqztbf6pmkgss3nv2scy/app.bsky.feed.post/3la5sxh4ica2r)
7373+ // AND THE MODERATION.BSKY.APP LABEL (at://did:plc:ujrpupcjf22a4riwjbupdv42/app.bsky.feed.post/3la5qntezsu2v)
7474+7175 private suspend fun handleGetFeedSkeleton(call: RoutingCall) {
7276 // TODO: Get requestor's DID from Authorization header.
7377 call.respond(buildFeedSkeleton("did:plc:zhxv5pxpmojhnvaqy4mwailv"))