Skip to content

Commit

Permalink
Fix Crash Issue when Seeing User's Videos in UserDetailsView (#15)
Browse files Browse the repository at this point in the history
* Update UserDetailView.swift

* Merge main workflows (#16)

* Update status-check.yml

* Update statuscheck-runner.yml

* Update CodeExt.swift

* Update UserDetailView.swift

Fixed optional unwrap issue

* Update status-check.yml

* Update status-check.yml

* Update status-check.yml

* Update status-check.yml

* Update status-check.yml

* Update status-check.yml

* Update UserDetailView.swift
  • Loading branch information
WindowsMEMZ authored Nov 29, 2023
1 parent 8b868eb commit 7fdf8d3
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 27 deletions.
50 changes: 48 additions & 2 deletions .github/workflows/status-check.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,34 @@
name: Status Check Workflow

on: workflow_call
on:
workflow_dispatch:
inputs:
psha:
required: true

jobs:
build:
name: Check Build
runs-on: macos-13
permissions:
checks: write
statuses: write
env:
FIN_STATUS: "error"
GH_TOKEN: ${{ github.token }}
steps:
- name: Update Check Status
run: |
gh api \
--method POST \
-H "Accept: application/vnd.github+json" \
-H "X-GitHub-Api-Version: 2022-11-28" \
/repos/${{ github.repository }}/statuses/$GITHUB_SHA \
-f state='pending' \
-f target_url='https://github.com/Darock-Studio/Darock-Bili/actions/runs/${{ github.run_id }}' \
-f description='Building...' \
-f context='API Status Checker'
- name: Checkout
uses: actions/checkout@v3

Expand All @@ -19,8 +41,32 @@ jobs:
key: check-build-cache
path: |
~/Library/Developer/Xcode/DerivedData
- name: Cache Package Caches
uses: actions/cache@v3
with:
path: .build
key: ${{ runner.os }}-spm-${{ hashFiles('**/Package.resolved') }}
restore-keys: |
${{ runner.os }}-spm-
- name: Update Status Env
run: echo "FIN_STATUS=failure" >> $GITHUB_ENV

- name: Build DarockBili App
run: |
xcodebuild -scheme 'DarockBili Watch App' -configuration Release build CODE_SIGN_IDENTITY=""
echo "FIN_STATUS=success" >> $GITHUB_ENV
- name: Update Check Status
if: always()
run: |
gh api \
--method POST \
-H "Accept: application/vnd.github+json" \
-H "X-GitHub-Api-Version: 2022-11-28" \
/repos/${{ github.repository }}/statuses/$GITHUB_SHA \
-f state='${{ env.FIN_STATUS }}' \
-f target_url='https://github.com/Darock-Studio/Darock-Bili/actions/runs/${{ github.run_id }}' \
-f context='API Status Checker'
28 changes: 25 additions & 3 deletions .github/workflows/statuscheck-runner.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,31 @@ jobs:
echo "The comment content contains the specified text. Continuing with further actions."
echo "::set-output name=shouldc::true"
fi
call-check-workflow:
name: Run
get-head-sha:
name: Get Pull Request Head SHA
needs: checkif
if: ${{ needs.checkif.outputs.shouldc == 'true' }}
uses: Darock-Studio/Darock-Bili/.github/workflows/status-check.yml@main
runs-on: ubuntu-latest
outputs:
psha: ${{ steps.getsha.outputs.psha }}
env:
slink: ${{ github.event.issue.pull_request.url }}
steps:
- name: Get SHA
id: getsha
run: |
json_data=$(curl -s "$slink")
sha=$(echo "$json_data" | jq -r '.head.ref')
echo "psha=$sha" >> $GITHUB_OUTPUT
call-check-workflow:
name: Call Check Overflow
needs: get-head-sha
runs-on: ubuntu-latest
steps:
- name: Call
uses: benc-uk/workflow-dispatch@v1
with:
workflow: status-check.yml
ref: ${{ needs.get-head-sha.outputs.psha }}
inputs: '{ "psha": "${{ needs.get-head-sha.outputs.psha }}"}'

20 changes: 0 additions & 20 deletions DarockBili Watch App/Extension/CodeExt.swift
Original file line number Diff line number Diff line change
Expand Up @@ -248,24 +248,4 @@ extension Int {
}
}

postfix operator /
extension Optional {
static postfix func / (opt: Int?) -> Int {
return opt ?? 0
}
static postfix func / (opt: String?) -> String {
return opt ?? ""
}
static postfix func / (opt: Double?) -> Double {
return opt ?? 0.0
}
static postfix func / (opt: Float?) -> Float {
return opt ?? 0.0
}
static postfix func / (opt: Bool?) -> Bool {
return opt ?? false
}
}



13 changes: 11 additions & 2 deletions DarockBili Watch App/PersonalCenter/UserDetailView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -560,19 +560,24 @@ struct UserDetailView: View {
func RefreshVideos() {
videos = [[String: String]]()
let headers: HTTPHeaders = [
"cookie": "SESSDATA=\(sessdata);"
"cookie": "SESSDATA=\(sessdata);",
"User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.0 Safari/605.1.15"
]
DarockKit.Network.shared.requestString("https://api.darock.top/bili/wbi/sign/\("mid=\(uid)&ps=50&pn=\(videoNowPage)".base64Encoded())") { respStr, isSuccess in
if isSuccess {
debugPrint(respStr.apiFixed())
DarockKit.Network.shared.requestJSON("https://api.bilibili.com/x/space/wbi/arc/search?\(respStr.apiFixed())", headers: headers) { respJson, isSuccess in
if isSuccess {
debugPrint(respJson)
if (respJson["code"].int ?? 0) != 0 {
tipWithText("加载失败:\(respJson["message"].string ?? "")", symbol: "xmark.circle.fill")
return
}
let vlist = respJson["data"]["list"]["vlist"]
for video in vlist {
videos.append(["Title": video.1["title"].string ?? "[加载失败]", "Length": video.1["length"].string ?? "E", "PlayCount": String(video.1["play"].int ?? -1), "PicUrl": video.1["pic"].string ?? "E", "BV": video.1["bvid"].string ?? "E", "Timestamp": String(video.1["created"].int ?? 0), "DanmakuCount": String(video.1["video_review"].int ?? -1)])
}
debugPrint(respJson["data"]["page"]["count"].int!)
debugPrint(respJson["data"]["page"]["count"].int ?? 0)
videoTotalPage = Int((respJson["data"]["page"]["count"].int ?? 0) / 50) + 1
videoCount = respJson["data"]["page"]["count"].int ?? 0
if !isVideosLoaded {
Expand All @@ -597,6 +602,10 @@ struct UserDetailView: View {
DarockKit.Network.shared.requestJSON("https://api.bilibili.com/x/space/wbi/article?\(respStr.apiFixed())", headers: headers) { respJson, isSuccess in
if isSuccess {
debugPrint(respJson)
if (respJson["code"].int ?? 0) != 0 {
tipWithText("加载失败:\(respJson["message"].string ?? "")", symbol: "xmark.circle.fill")
return
}
let articlesJson = respJson["data"]["articles"]
for article in articlesJson {
articles.append(["Title": article.1["title"].string ?? "[加载失败]", "Summary": article.1["summary"].string ?? "[加载失败]", "Type": article.1["categories"][0]["name"].string ?? "[加载失败]", "View": String(article.1["stats"]["view"].int ?? -1), "Like": String(article.1["stats"]["like"].int ?? -1), "Pic": article.1["image_urls"][0].string ?? "E", "CV": String(article.1["id"].int ?? 0)])
Expand Down

0 comments on commit 7fdf8d3

Please sign in to comment.