Skip to content

Commit

Permalink
Merge branch 'main' into sleep-notification
Browse files Browse the repository at this point in the history
  • Loading branch information
WindowsMEMZ authored Feb 10, 2024
2 parents 251fe4d + f90ca60 commit 4f20022
Show file tree
Hide file tree
Showing 9 changed files with 779 additions and 66 deletions.
4 changes: 2 additions & 2 deletions DarockBili Watch App/Bangumi/BangumiDetailView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ struct BangumiDetailView: View {
}
} detail: {
if let data = navigationSelectedEpdata, let aid = data.aid {
VideoCommentsView(oid: av2bv(avid: UInt64(aid)))
CommentsView(oid: av2bv(avid: UInt64(aid)))
} else {
Text("Bangumi.comments.select")
}
Expand Down Expand Up @@ -176,7 +176,7 @@ struct BangumiDetailView: View {
.listRowBackground(Color.clear)
ForEach(0..<epDatas.count, id: \.self) { i in
if let aid = epDatas[i].aid {
NavigationLink(destination: {VideoCommentsView(oid: av2bv(avid: UInt64(aid)))}, label: {
NavigationLink(destination: {CommentsView(oid: av2bv(avid: UInt64(aid)))}, label: {
Text(epDatas[i].longTitle)
})
}
Expand Down
16 changes: 16 additions & 0 deletions DarockBili Watch App/Extension/UIExt.swift
Original file line number Diff line number Diff line change
Expand Up @@ -198,3 +198,19 @@ extension Indicator where T == ProgressView<EmptyView, EmptyView> {
}
}
}

struct UIImageTransfer: Transferable {
let image: UIImage
enum TransferError: Error {
case importFailed
}

static var transferRepresentation: some TransferRepresentation {
DataRepresentation(importedContentType: .image) { data in
guard let uiImage = UIImage(data: data) else {
throw TransferError.importFailed
}
return UIImageTransfer(image: uiImage)
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// VideoCommentsView.swift
// CommentsView.swift
// DarockBili Watch App
//
// Created by WindowsMEMZ on 2023/7/2.
Expand All @@ -22,8 +22,9 @@ import Alamofire
import SwiftyJSON
import SDWebImageSwiftUI

struct VideoCommentsView: View {
struct CommentsView: View {
var oid: String
var type: Int = 1
@AppStorage("DedeUserID") var dedeUserID = ""
@AppStorage("DedeUserID__ckMd5") var dedeUserID__ckMd5 = ""
@AppStorage("SESSDATA") var sessdata = ""
Expand All @@ -32,31 +33,31 @@ struct VideoCommentsView: View {
var body: some View {
VStack {
if #available(watchOS 10, *) {
CommentMainView(oid: oid)
CommentMainView(oid: oid, type: type)
.toolbar {
ToolbarItem(placement: .topBarTrailing) {
Button(action: {
isSendCommentPresented = true
}, label: {
Image(systemName: "square.and.pencil")
})
.sheet(isPresented: $isSendCommentPresented, content: {CommentSendView(oid: oid)})
.sheet(isPresented: $isSendCommentPresented, content: {CommentSendView(oid: oid, type: type)})
}
}
} else {
CommentMainView(oid: oid)
CommentMainView(oid: oid, type: type)
}
}

}

struct CommentMainView: View {
var oid: String
var type: Int
@AppStorage("DedeUserID") var dedeUserID = ""
@AppStorage("DedeUserID__ckMd5") var dedeUserID__ckMd5 = ""
@AppStorage("SESSDATA") var sessdata = ""
@AppStorage("bili_jct") var biliJct = ""
@State var avid: UInt64 = 0
@State var id = ""
@State var comments = [[String: String]]()
@State var sepTexts = [[String]]()
@State var emojiUrls = [[String]]()
Expand All @@ -79,7 +80,7 @@ struct VideoCommentsView: View {
Text("Comment.send")
}
})
.sheet(isPresented: $isSendCommentPresented, content: {CommentSendView(oid: oid)})
.sheet(isPresented: $isSendCommentPresented, content: {CommentSendView(oid: oid, type: type)})
}
if comments.count != 0 {
ForEach(0...comments.count - 1, id: \.self) { i in
Expand Down Expand Up @@ -133,7 +134,7 @@ struct VideoCommentsView: View {
if commentReplies[i].count != 0 {
VStack {
ForEach(0...commentReplies[i].count - 1, id: \.self) { j in
NavigationLink(destination: {CommentRepliesView(avid: avid, replies: commentReplies[i], goto: commentReplies[i][j]["Rpid"]!)}, label: {
NavigationLink(destination: {CommentRepliesView(avid: id, type: type, replies: commentReplies[i], goto: commentReplies[i][j]["Rpid"]!)}, label: {
HStack {
Text("\(Text(commentReplies[i][j]["Sender"]! + ":").foregroundColor(.blue)) \(commentReplies[i][j]["Text"]!)")
.font(.system(size: 12))
Expand Down Expand Up @@ -162,7 +163,7 @@ struct VideoCommentsView: View {
"cookie": "SESSDATA=\(sessdata)",
"User-Agent": "Mozilla/5.0 (X11; CrOS x86_64 14541.0.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36"
]
AF.request("https://api.bilibili.com/x/v2/reply/action", method: .post, parameters: BiliCommentLike(oid: avid, rpid: Int(comments[i]["Rpid"]!)!, action: comments[i]["UserAction"]! == "1" ? 0 : 1, csrf: biliJct), headers: headers).response { response in
AF.request("https://api.bilibili.com/x/v2/reply/action", method: .post, parameters: BiliCommentLike(type: type, oid: id, rpid: Int(comments[i]["Rpid"]!)!, action: comments[i]["UserAction"]! == "1" ? 0 : 1, csrf: biliJct), headers: headers).response { response in
debugPrint(response)
comments[i]["UserAction"]! = comments[i]["UserAction"]! == "1" ? "0" : "1"
}
Expand All @@ -177,7 +178,7 @@ struct VideoCommentsView: View {
"cookie": "SESSDATA=\(sessdata)",
"User-Agent": "Mozilla/5.0 (X11; CrOS x86_64 14541.0.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36"
]
AF.request("https://api.bilibili.com/x/v2/reply/hate", method: .post, parameters: BiliCommentLike(oid: avid, rpid: Int(comments[i]["Rpid"]!)!, action: comments[i]["UserAction"]! == "2" ? 0 : 1, csrf: biliJct), headers: headers).response { response in
AF.request("https://api.bilibili.com/x/v2/reply/hate", method: .post, parameters: BiliCommentLike(type: type, oid: id, rpid: Int(comments[i]["Rpid"]!)!, action: comments[i]["UserAction"]! == "2" ? 0 : 1, csrf: biliJct), headers: headers).response { response in
debugPrint(response)
comments[i]["UserAction"]! = comments[i]["UserAction"]! == "2" ? "0" : "2"
}
Expand Down Expand Up @@ -219,13 +220,17 @@ struct VideoCommentsView: View {
}

func ContinueLoadComment() {
avid = bv2av(bvid: oid)
debugPrint(avid)
if Int(oid) == nil, type == 1 {
id = String(bv2av(bvid: oid))
} else {
id = oid
}
debugPrint(id)
let headers: HTTPHeaders = [
"cookie": "SESSDATA=\(sessdata);",
"User-Agent": "Mozilla/5.0 (X11; CrOS x86_64 14541.0.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36"
]
DarockKit.Network.shared.requestJSON("https://api.bilibili.com/x/v2/reply?type=1&oid=\(avid)&sort=1&ps=20&pn=\(nowPage)", headers: headers) { respJson, isSuccess in
DarockKit.Network.shared.requestJSON("https://api.bilibili.com/x/v2/reply?type=\(type)&oid=\(id)&sort=1&ps=20&pn=\(nowPage)", headers: headers) { respJson, isSuccess in
if isSuccess {
debugPrint(respJson)
if !CheckBApiError(from: respJson) { return }
Expand Down Expand Up @@ -282,7 +287,8 @@ struct VideoCommentsView: View {
}

struct CommentRepliesView: View {
var avid: UInt64
var avid: String
var type: Int
@State var replies: [[String: String]]
var goto: String? = nil
@AppStorage("DedeUserID") var dedeUserID = ""
Expand Down Expand Up @@ -357,7 +363,7 @@ struct VideoCommentsView: View {
"cookie": "SESSDATA=\(sessdata)",
"User-Agent": "Mozilla/5.0 (X11; CrOS x86_64 14541.0.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36"
]
AF.request("https://api.bilibili.com/x/v2/reply/action", method: .post, parameters: BiliCommentLike(oid: avid, rpid: Int(replies[i]["Rpid"]!)!, action: replies[i]["UserAction"]! == "1" ? 0 : 1, csrf: biliJct), headers: headers).response { response in
AF.request("https://api.bilibili.com/x/v2/reply/action", method: .post, parameters: BiliCommentLike(type: type, oid: avid, rpid: Int(replies[i]["Rpid"]!)!, action: replies[i]["UserAction"]! == "1" ? 0 : 1, csrf: biliJct), headers: headers).response { response in
debugPrint(response)
replies[i]["UserAction"]! = replies[i]["UserAction"]! == "1" ? "0" : "1"
}
Expand All @@ -372,7 +378,7 @@ struct VideoCommentsView: View {
"cookie": "SESSDATA=\(sessdata)",
"User-Agent": "Mozilla/5.0 (X11; CrOS x86_64 14541.0.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36"
]
AF.request("https://api.bilibili.com/x/v2/reply/hate", method: .post, parameters: BiliCommentLike(oid: avid, rpid: Int(replies[i]["Rpid"]!)!, action: replies[i]["UserAction"]! == "2" ? 0 : 1, csrf: biliJct), headers: headers).response { response in
AF.request("https://api.bilibili.com/x/v2/reply/hate", method: .post, parameters: BiliCommentLike(type: type, oid: avid, rpid: Int(replies[i]["Rpid"]!)!, action: replies[i]["UserAction"]! == "2" ? 0 : 1, csrf: biliJct), headers: headers).response { response in
debugPrint(response)
replies[i]["UserAction"]! = replies[i]["UserAction"]! == "2" ? "0" : "2"
}
Expand Down Expand Up @@ -407,14 +413,15 @@ struct VideoCommentsView: View {
}
struct CommentSendView: View {
var oid: String
var type: Int
@Environment(\.dismiss) var dismiss
@AppStorage("DedeUserID") var dedeUserID = ""
@AppStorage("DedeUserID__ckMd5") var dedeUserID__ckMd5 = ""
@AppStorage("SESSDATA") var sessdata = ""
@AppStorage("bili_jct") var biliJct = ""
@State var sendCommentCache = ""
@State var isSendingComment = false
@State var avid: UInt64 = 0
@State var id = ""
var body: some View {
VStack {
if !isSendingComment {
Expand All @@ -425,7 +432,7 @@ struct VideoCommentsView: View {
"cookie": "SESSDATA=\(sessdata)",
"User-Agent": "Mozilla/5.0 (X11; CrOS x86_64 14541.0.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36"
]
AF.request("https://api.bilibili.com/x/v2/reply/add", method: .post, parameters: BiliSubmitComment(oid: avid, message: sendCommentCache, csrf: biliJct), headers: headers).response { response in
AF.request("https://api.bilibili.com/x/v2/reply/add", method: .post, parameters: BiliSubmitComment(type: type, oid: id, message: sendCommentCache, csrf: biliJct), headers: headers).response { response in
sendCommentCache = ""
debugPrint(response)
isSendingComment = false
Expand All @@ -439,32 +446,36 @@ struct VideoCommentsView: View {
}
}
.onAppear {
avid = bv2av(bvid: oid)
debugPrint(avid)
if Int(oid) == nil, type == 1 {
id = String(bv2av(bvid: oid))
} else {
id = oid
}
debugPrint(id)
}
}
}
}

struct BiliCommentLike: Codable {
var type: Int = 1
let oid: UInt64
var type: Int
let oid: String
let rpid: Int
let action: Int
let csrf: String
}

struct BiliSubmitComment: Codable {
var type: Int = 1
let oid: UInt64
var type: Int
let oid: String
var root: Int? = nil
var parent: Int? = nil
let message: String
let csrf: String
}

struct VideoCommentsView_Previews: PreviewProvider {
struct CommentsView_Previews: PreviewProvider {
static var previews: some View {
VideoCommentsView(oid: "1tV4y1379v")
CommentsView(oid: "1tV4y1379v")
}
}
Loading

0 comments on commit 4f20022

Please sign in to comment.