Skip to content
This repository has been archived by the owner on Oct 3, 2023. It is now read-only.

Commit

Permalink
Merge pull request #506 from langningchen/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
Chen LangNing authored Sep 24, 2023
2 parents ec310b6 + a42ecd1 commit 2c84df6
Show file tree
Hide file tree
Showing 16 changed files with 196 additions and 285 deletions.
4 changes: 2 additions & 2 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
version: 2
updates:
- package-ecosystem: "npm"
directory: "/Server"
- package-ecosystem: "npm"
directory: "/Server"
target-branch: "dev"
schedule:
interval: "weekly"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@
name: AutoLabel
name: AutoLabelIssue
on:
issue_comment:
types:
- created
- edited
jobs:
AutoLabel:
name: AutoLabel
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
with:
fetch-depth: 0
- name: AutoLabel
run: |
- run: |
cd ./Update
npm install
node ./AutoLabel.js ${{ secrets.GITHUB_TOKEN }}
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
name: SetPRLabel
name: AutoLabelPR
on:
pull_request:
types:
- opened
- reopened
- synchronize
jobs:
SetPRLabel:
name: SetPRLabel
AutoLabelPR:
runs-on: ubuntu-latest
steps:
- name: Set PR labels
uses: actions/labeler@v4
- uses: actions/labeler@v4
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
dot: true
27 changes: 27 additions & 0 deletions .github/workflows/Daily.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Daily
on:
schedule:
- cron: 0 0 * * *
workflow_dispatch:
jobs:
DeleteActions:
runs-on: ubuntu-latest
steps:
- name: DeleteActions
run: |
echo ${{ secrets.GITHUB_TOKEN }} | gh auth login --with-token
for WorkflowRun in $(gh api repos/${{ github.repository }}/actions/runs --paginate -q '.workflow_runs[] | select(.status == "completed") | select(.name | contains("AutoLabelIssue") or contains("AuthLabelPR") or contains("UpdateToRelease") or contains("UpdateVersion")) | "\(.id)"')
do
gh api --method DELETE /repos/${{ github.repository }}/actions/runs/$WorkflowRun
done
Stale:
runs-on: ubuntu-latest
permissions:
issues: write
pull-requests: write
steps:
- uses: actions/stale@v8
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
days-before-stale: 7
exempt-issue-labels: frozen
14 changes: 0 additions & 14 deletions .github/workflows/DeleteActions.yml

This file was deleted.

8 changes: 3 additions & 5 deletions .github/workflows/DependencyScan.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Dependency Review
name: DependencyScan
on:
pull_request:
types:
Expand All @@ -9,7 +9,5 @@ jobs:
dependency-review:
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v3
- name: Dependency Review
uses: actions/dependency-review-action@v3
- uses: actions/checkout@v3
- uses: actions/dependency-review-action@v3
20 changes: 6 additions & 14 deletions .github/workflows/Prerelease.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,18 @@ on:
- dev
paths:
- XMOJ.user.js
workflow_dispatch:
jobs:
prerelease:
name: Prerelease
Prerelease:
runs-on: ubuntu-latest
permissions: write-all
steps:
- name: Checkout
uses: actions/checkout@v2
- uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Get version
id: get_version
run: node ./Update/GetVersion.js
- name: Create Release
id: create_release
- id: create_release
uses: softprops/action-gh-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Expand All @@ -31,12 +27,8 @@ jobs:
prerelease: true
files: XMOJ.user.js
target_commitish: ${{ github.sha }}
- name: Setup Pages
uses: actions/configure-pages@v3
- name: Upload artifact
uses: actions/upload-pages-artifact@v2
- uses: actions/configure-pages@v3
- uses: actions/upload-pages-artifact@v2
with:
path: .
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v2
- uses: actions/deploy-pages@v2
24 changes: 7 additions & 17 deletions .github/workflows/Release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,45 +5,35 @@ on:
- master
paths:
- XMOJ.user.js
workflow_dispatch:
jobs:
release:
name: Release
Release:
runs-on: ubuntu-latest
permissions: write-all
steps:
- name: Checkout
uses: actions/checkout@v2
- uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Get version
id: get_version
run: node ./Update/GetVersion.js
- name: Create Release
id: create_release
- id: create_release
uses: softprops/action-gh-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ steps.get_version.outputs.version }}
name: ${{ steps.get_version.outputs.version }}
generate_release_notes: true
draft: false
prerelease: false
files: XMOJ.user.js
- name: Publish to Cloudflare Pages
uses: cloudflare/pages-action@v1
- uses: cloudflare/pages-action@v1
with:
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
accountId: f871a3498aa79883e7f4f0fbe8a465a4
projectName: xmoj-script-web
directory: .
- name: Setup Pages
uses: actions/configure-pages@v3
- name: Upload artifact
uses: actions/upload-pages-artifact@v2
- uses: actions/configure-pages@v3
- uses: actions/upload-pages-artifact@v2
with:
path: .
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v2
- uses: actions/deploy-pages@v2
17 changes: 0 additions & 17 deletions .github/workflows/Stale.yml

This file was deleted.

5 changes: 2 additions & 3 deletions .github/workflows/UpdateToRelease.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,18 @@ on:
pull_request:
types:
- opened
- reopened
- synchronize
branches:
- master
jobs:
UpdateToRelease:
name: UpdateToRelease
runs-on: ubuntu-latest
permissions:
pull-requests: write
contents: write
steps:
- name: Checkout
uses: actions/checkout@v2
- uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Update to release
Expand Down
5 changes: 1 addition & 4 deletions .github/workflows/UpdateVersion.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,8 @@ on:
- dev
jobs:
UpdateVersion:
name: UpdateVersion
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- uses: actions/checkout@v2
- name: Update version
id: update_version
run: node ./Update/UpdateVersion.js ${{ secrets.GITHUB_TOKEN }} ${{ github.event.number }} "${{ github.event.pull_request.title }}"
4 changes: 3 additions & 1 deletion Server/Source/Initial.sql
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ CREATE TABLE bbs_reply (
post_id INTEGER NOT NULL,
user_id TEXT NOT NULL,
content TEXT NOT NULL,
reply_time INTEGER NOT NULL
reply_time INTEGER NOT NULL,
edit_time INTEGER,
edit_person TEXT
);

DROP TABLE IF EXISTS phpsessid;
Expand Down
33 changes: 10 additions & 23 deletions Server/Source/Process.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ export class Process {
this.SessionID = Data["SessionID"];
this.Username = Data["Username"];
// return new Result(true, "令牌检测跳过");
let tokenHash:string = MD5(this.SessionID).toString();
let HashedToken: string = MD5(this.SessionID).toString();
let CurrentSessionData = ThrowErrorIfFailed(await this.XMOJDatabase.Select("phpsessid", ["user_id", "create_time"], {
token: tokenHash
token: HashedToken
}));
if (CurrentSessionData.toString() !== "") {
if (CurrentSessionData[0]["user_id"] === this.Username &&
Expand All @@ -65,7 +65,7 @@ export class Process {
}
else {
ThrowErrorIfFailed(await this.XMOJDatabase.Delete("phpsessid", {
token: tokenHash
token: HashedToken
}));
Output.Log("Session " + this.SessionID + " expired");
}
Expand Down Expand Up @@ -97,7 +97,7 @@ export class Process {
return new Result(false, "令牌不匹配");
}
ThrowErrorIfFailed(await this.XMOJDatabase.Insert("phpsessid", {
token: tokenHash,
token: HashedToken,
user_id: this.Username,
create_time: new Date().getTime()
}));
Expand Down Expand Up @@ -294,19 +294,11 @@ export class Process {
return new Result(false, "内容不能为空");
}
let MentionPeople = new Array<string>();
let StringToReplace = new Array<string>();
for (let Match of String(Data["Content"]).matchAll(/@([a-zA-Z0-9]+)/g)) {
if (ThrowErrorIfFailed(await this.IfUserExist(Match[1]))["Exist"]) {
MentionPeople.push(Match[1]);
StringToReplace.push(" <a class=\"link-info\" href=\"http://www.xmoj.tech/userinfo.php?user=" + Match[1] + "\">@" + Match[1] + "</a> ");
}
else {
StringToReplace.push("@" + Match[1]);
}
}
Data["Content"] = String(Data["Content"]).replace(/@([a-zA-Z0-9]+)/g, (Match) => {
return StringToReplace.shift() || "";
});
MentionPeople = Array.from(new Set(MentionPeople));
let ReplyID = ThrowErrorIfFailed(await this.XMOJDatabase.Insert("bbs_reply", {
user_id: this.Username,
Expand Down Expand Up @@ -448,7 +440,9 @@ export class Process {
ReplyID: ReplyItem["reply_id"],
UserID: ReplyItem["user_id"],
Content: ReplyItem["content"],
ReplyTime: ReplyItem["reply_time"]
ReplyTime: ReplyItem["reply_time"],
EditTime: ReplyItem["edit_time"],
EditPerson: ReplyItem["edit_person"]
});
}
return new Result(true, "获得讨论成功", ResponseData);
Expand Down Expand Up @@ -530,22 +524,15 @@ export class Process {
return new Result(false, "内容不能为空");
}
let MentionPeople = new Array<string>();
let StringToReplace = new Array<string>();
for (let Match of String(Data["Content"]).matchAll(/@([a-zA-Z0-9]+)/g)) {
if (ThrowErrorIfFailed(await this.IfUserExist(Match[1]))["Exist"]) {
MentionPeople.push(Match[1]);
StringToReplace.push(" <a class=\"link-info\" href=\"http://www.xmoj.tech/userinfo.php?user=" + Match[1] + "\">@" + Match[1] + "</a> ");
}
else {
StringToReplace.push("@" + Match[1]);
}
}
Data["Content"] = String(Data["Content"]).replace(/@([a-zA-Z0-9]+)/g, (Match) => {
return StringToReplace.shift() || "";
});
Data["Content"] = String(Data["Content"]).trim() + "\n<br><span class=\"text-muted\" style=\"font-size: 12px\">已于 " + new Date().toLocaleString() + " 编辑</span>";
await this.XMOJDatabase.Update("bbs_reply", {
content: Data["Content"]
content: Data["Content"],
edit_time: new Date().getTime(),
edit_person: this.Username
}, {
reply_id: Data["ReplyID"]
});
Expand Down
Loading

0 comments on commit 2c84df6

Please sign in to comment.