Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Utils new #7

Merged
merged 7 commits into from
Jan 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions .github/workflows/autoupdatereadme.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: auto-update-readme

permissions: write-all

on:
pull_request:
types: [opened, reopened, synchronize]
workflow_dispatch:

jobs:
update:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- name: Use Node.js
uses: actions/setup-node@v4
with:
node-version: '20.x'
- run: node --version
- run: corepack enable
- run: pnpm i
- run: pnpm copyreadme

- name: Check for changes
id: check_changes
run: |
if [[ -n $(git status --porcelain) ]]; then
echo "Changes detected."
echo "::set-output name=changed::true"
else
echo "No changes detected."
echo "::set-output name=changed::false"
fi

- name: Commit changes
if: steps.check_changes.outputs.changed == 'true'
run: |
git config --global user.name "GitHub Actions"
git config --global user.email "actions@github.com"
git add README.md
git commit -m 'update js code'
git push
22 changes: 22 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: test

on:
pull_request:
types: [opened, reopened, synchronize]
workflow_dispatch:

jobs:
test:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- name: Use Node.js
uses: actions/setup-node@v4
with:
node-version: '20.x'
- run: node --version
- run: corepack enable
- run: pnpm i
- run: pnpm test
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ esm
cjs
test.js
*.tsbuildinfo
dist
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ scu-pecourse-utils-dom | 通过实例获取方法

在选课前十分钟登录选课系统,进入选课界面。复制下面的代码

<!-- PLACEHOLDER-S -->
```javascript
/**
* 在console中使用的代码
Expand Down Expand Up @@ -69,7 +70,8 @@ function choose(courseClassId, teacherUid, teacherName, studentUid) {
});
});
}
;((teacherName) => {

!((teacherName) => {
const { courseClassId, teacherUid } =
getClassIdAndTeacherIdByDOM(teacherName);
const { username } = getUser();
Expand All @@ -94,8 +96,9 @@ function choose(courseClassId, teacherUid, teacherName, studentUid) {
}
}, 1000);
})('夏廷富');

```
<!-- PLACEHOLDER-E -->

把复制下来的代码最后一行的老师名字改成自己想选的课的老师名字。

在选课页面打开浏览器的调试模式(一般是按F12)。在右边的调试界面里面选择console(控制台),把刚才改好的代码复制到console里面,在选课前1-3分钟之内按回车运行代码,代码成功运行后会有输出。等能选课之后会自动选课成功并输出。此时可以刷新页面去确定选课结果
Expand Down
9 changes: 6 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
{
"name": "@scu-pecourse/pe-course",
"version": "1.0.2",
"name": "@xiaochuan-dev/scu-pe-course",
"version": "0.0.1",
"license": "GPL-3.0",
"private": true,
"packageManager": "pnpm@9.12.2",
"devDependencies": {
"@types/jest": "^29.5.14",
"@types/node": "^22.10.5",
"esbuild": "^0.24.2",
"jest": "^29.7.0",
"prettier": "^2.3.2",
"ts-jest": "^29.2.5",
"typescript": "^5.7.2"
},
"scripts": {
"test": "jest",
"format": "prettier --write packages/"
"format": "prettier --write packages/",
"copyreadme": "esbuild scripts/**/*.ts --outdir=dist --bundle --format=cjs --platform=node && node dist/insertConsoleToReadme.js"
}
}
3 changes: 2 additions & 1 deletion packages/scu-pecourse-utils-console/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ function choose(courseClassId, teacherUid, teacherName, studentUid) {
});
});
}
;((teacherName) => {

!((teacherName) => {
const { courseClassId, teacherUid } =
getClassIdAndTeacherIdByDOM(teacherName);
const { username } = getUser();
Expand Down
16 changes: 11 additions & 5 deletions packages/scu-pecourse-utils/__tests__/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
import { jwt_secret, app_key, app_secret, createScuPeJWT, getSign } from '../src';
import {
jwt_secret,
app_key,
app_secret,
createScuPeJWT,
getSign,
} from '../src';

describe('test constants', () => {

it('test jwt_secret', () => {
expect(jwt_secret).toBe('098f6bcd4621d373cade4e832627b4f6');
});
Expand All @@ -13,7 +18,6 @@ describe('test constants', () => {
it('test app_secret', () => {
expect(app_secret).toBe('7cd476ab866b49d7a9788ad9f4789495');
});

});

describe('test jwt', () => {
Expand All @@ -24,7 +28,8 @@ describe('test jwt', () => {

const jwtToken = createScuPeJWT({ id, exp, nbf });

const rightToken = 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJyb2xlIjoiMSIsIm5hbWUiOiIwMDAwMDAwMDAwMDAwIiwidXNlcmlkIjoiMDAwMDAwMDAwMDAwMCIsImlzcyI6InJlc3RhcGl1c2VyIiwiYXVkIjoiMDk4ZjZiY2Q0NjIxZDM3M2NhZGU0ZTgzMjYyN2I0ZjYiLCJleHAiOjE3MzY0MDE0MzYsIm5iZiI6MTczNjIyODYzNn0.mPK2ciBvEaKn2yA0MkT7hKNYkwCzfTO2wD0hSqh7U_4';
const rightToken =
'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJyb2xlIjoiMSIsIm5hbWUiOiIwMDAwMDAwMDAwMDAwIiwidXNlcmlkIjoiMDAwMDAwMDAwMDAwMCIsImlzcyI6InJlc3RhcGl1c2VyIiwiYXVkIjoiMDk4ZjZiY2Q0NjIxZDM3M2NhZGU0ZTgzMjYyN2I0ZjYiLCJleHAiOjE3MzY0MDE0MzYsIm5iZiI6MTczNjIyODYzNn0.mPK2ciBvEaKn2yA0MkT7hKNYkwCzfTO2wD0hSqh7U_4';

expect(jwtToken).toBe(rightToken);
});
Expand All @@ -36,7 +41,8 @@ describe('test jwt', () => {

const jwtToken = createScuPeJWT({ id, exp, nbf });

const rightToken = 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJyb2xlIjoiMSIsIm5hbWUiOiIxMTExMTExMTExMTExIiwidXNlcmlkIjoiMTExMTExMTExMTExMSIsImlzcyI6InJlc3RhcGl1c2VyIiwiYXVkIjoiMDk4ZjZiY2Q0NjIxZDM3M2NhZGU0ZTgzMjYyN2I0ZjYiLCJleHAiOjE3MzY0MDE0MzYsIm5iZiI6MTczNjIyODYzNn0.KFiRFmnuVXGZFS8Xia5cpe1xolVQUldpTWxlORLY2HU';
const rightToken =
'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJyb2xlIjoiMSIsIm5hbWUiOiIxMTExMTExMTExMTExIiwidXNlcmlkIjoiMTExMTExMTExMTExMSIsImlzcyI6InJlc3RhcGl1c2VyIiwiYXVkIjoiMDk4ZjZiY2Q0NjIxZDM3M2NhZGU0ZTgzMjYyN2I0ZjYiLCJleHAiOjE3MzY0MDE0MzYsIm5iZiI6MTczNjIyODYzNn0.KFiRFmnuVXGZFS8Xia5cpe1xolVQUldpTWxlORLY2HU';

expect(jwtToken).toBe(rightToken);
});
Expand Down
4 changes: 2 additions & 2 deletions packages/scu-pecourse-utils/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@scu-pecourse/utils",
"version": "1.0.6",
"name": "@xiaochuan-dev/scu-pecourse-utils",
"version": "0.0.1",
"license": "GPL-3.0",
"exports": {
".": {
Expand Down
2 changes: 1 addition & 1 deletion packages/scu-pecourse-utils/src/action/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ export function findTeacher(findTeacherName: string, courses: Course[]) {
}
}
return null;
}
}
4 changes: 2 additions & 2 deletions packages/scu-pecourse-utils/src/utils/jwt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ export function createScuPeJWT({
nbf: number;
}) {
const header = {
typ: "JWT",
alg: "HS256",
typ: 'JWT',
alg: 'HS256',
};
const secret = jwt_secret;
const payload = {
Expand Down
2 changes: 1 addition & 1 deletion packages/scu-pecourse-utils/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
"rootDir": "src"
},
"include": ["src"]
}
}
Loading
Loading