Skip to content

Commit

Permalink
🔖 bump version to 1.2.1
Browse files Browse the repository at this point in the history
  • Loading branch information
ManiaciaChao committed Mar 23, 2021
1 parent 85aca3c commit 39301c1
Show file tree
Hide file tree
Showing 5 changed files with 105 additions and 40 deletions.
21 changes: 12 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@
## Features

* Multi-mode sign-in support: normal, GPS and QR code.
* Sign in **WITHOUT any assistance** from your classmates
* System-level notification support (test on windows 10 & macOS & gnome)
* Active development
* <del>Docker support</del>
- Multi-mode sign-in support: normal, GPS and QR code.
- Sign in **WITHOUT any assistance** from your classmates
- System-level notification support (test on windows 10 & macOS & gnome)
- Active development
- <del>Docker support</del>

## Install

Expand Down Expand Up @@ -78,9 +78,11 @@ env OPEN_ID=${your openId} yarn start

For normal & GPS sign-in, the process is automatic. You don't need to care about anything.

If the `openId` is expired or invaild, you'll get a notification :)

### For QR Code sign-in

Due to the limitation of WeChat API, things are quite different for QR code sign-in.
Due to the limitation of WeChat API, things are quite different for QR code sign-in.

The script will subscribe the sign-in URL generated by teachermate's server, and print its corresponding QR code to the console when it updates.

Expand All @@ -94,12 +96,13 @@ via WeChat will causes the update of `openId`. You have to reacquire your new

👤 **maniacata**

* Website: http://blog.plus1sec.cn
* Github: [@ManiaciaChao](https://github.com/ManiaciaChao)
- Website: http://blog.plus1sec.cn
- Github: [@ManiaciaChao](https://github.com/ManiaciaChao)

## Show your support

Give a ⭐️ if this project helped you!

***
---

_This README was generated with ❤️ by [readme-md-generator](https://github.com/kefranabg/readme-md-generator)_
3 changes: 2 additions & 1 deletion dist/consts.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
var _a;
var _b;
Object.defineProperty(exports, "__esModule", { value: true });
exports.userAgent = exports.qr = exports.config = void 0;
exports.CHECK_ALIVE_INTERVAL = exports.userAgent = exports.qr = exports.config = void 0;
var fs_1 = require("fs");
var path_1 = require("path");
var configFile = fs_1.readFileSync(path_1.join("./", "config.json"));
Expand All @@ -13,3 +13,4 @@ exports.qr = (_a = exports.config.qr, _a === void 0 ? {
copyCmd: undefined,
} : _a);
exports.userAgent = (_b = exports.config.ua) !== null && _b !== void 0 ? _b : "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4427.5 Safari/537.36";
exports.CHECK_ALIVE_INTERVAL = 4; // request `/role` per a given amount of `/active_signs`
38 changes: 27 additions & 11 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ var main = function () { return __awaiter(void 0, void 0, void 0, function () {
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, requests_1.activeSign(openId)
.then(function (data) { return data.json(); })
.then(function (data) { return __awaiter(void 0, void 0, void 0, function () {
var queue, _loop_1, _i, queue_1, sign, state_1;
return __generator(this, function (_a) {
Expand Down Expand Up @@ -127,7 +126,6 @@ var main = function () { return __awaiter(void 0, void 0, void 0, function () {
case 3:
_a.sent();
return [4 /*yield*/, requests_1.signIn(openId, signInQuery)
.then(function (data) { return data.json(); })
.then(function (data) {
if (!data.errorCode || data.errorCode === 305) {
signedIdSet.add(signId);
Expand Down Expand Up @@ -171,17 +169,35 @@ var main = function () { return __awaiter(void 0, void 0, void 0, function () {
});
}); };
(function () { return __awaiter(void 0, void 0, void 0, function () {
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, main()];
var i, _a;
return __generator(this, function (_b) {
switch (_b.label) {
case 0:
i = 0;
_b.label = 1;
case 1:
_a.sent();
return [4 /*yield*/, utils_1.sleep(consts_1.config.interval)];
_a = i === 0;
if (!_a) return [3 /*break*/, 3];
return [4 /*yield*/, requests_1.checkInvaild(openId)];
case 2:
_a.sent();
_a.label = 3;
case 3: return [3 /*break*/, 0];
case 4: return [2 /*return*/];
_a = (_b.sent());
_b.label = 3;
case 3:
if (_a) {
sendNotificaition("Error: expired or invaild openId");
return [3 /*break*/, 7];
}
return [4 /*yield*/, main()];
case 4:
_b.sent();
return [4 /*yield*/, utils_1.sleep(consts_1.config.interval)];
case 5:
_b.sent();
_b.label = 6;
case 6:
i = (i + 1) % consts_1.CHECK_ALIVE_INTERVAL;
return [3 /*break*/, 1];
case 7: return [2 /*return*/];
}
});
}); })();
81 changes: 63 additions & 18 deletions dist/requests.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,40 +10,85 @@ var __assign = (this && this.__assign) || function () {
};
return __assign.apply(this, arguments);
};
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __generator = (this && this.__generator) || function (thisArg, body) {
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
function verb(n) { return function (v) { return step([n, v]); }; }
function step(op) {
if (f) throw new TypeError("Generator is already executing.");
while (_) try {
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
if (y = 0, t) op = [op[0] & 2, t.value];
switch (op[0]) {
case 0: case 1: t = op; break;
case 4: _.label++; return { value: op[1], done: false };
case 5: _.label++; y = op[1]; op = [0]; continue;
case 7: op = _.ops.pop(); _.trys.pop(); continue;
default:
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
if (t[2]) _.ops.pop();
_.trys.pop(); continue;
}
op = body.call(thisArg, _);
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
}
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.signIn = exports.activeSign = void 0;
exports.checkInvaild = exports.signIn = exports.activeSign = void 0;
var node_fetch_1 = __importDefault(require("node-fetch"));
var consts_1 = require("./consts");
var baseHeaders = {
"User-Agent": consts_1.userAgent,
"Content-Type": "application/json",
Accept: "*/*",
"Accept-Language": "zh-CN,en-US;q=0.7,en;q=0.3",
"Accept-Language": "zh-CN,en-US;qbaseHeaders=0.7,en;q=0.3",
};
var request = function (url, init) {
return node_fetch_1.default(url, init).then(function (data) { return data.json(); });
};
exports.activeSign = function (openId) {
return node_fetch_1.default("https://v18.teachermate.cn/wechat-api/v1/class-attendance/student/active_signs", {
headers: __assign(__assign({}, baseHeaders), { "Content-Type": "application/json", openId: openId, "If-None-Match": '"38-djBNGTNDrEJXNs9DekumVQ"', Referrer: "https://v18.teachermate.cn/wechat-pro-ssr/student/sign?openid=" + openId }),
return request("https://v18.teachermate.cn/wechat-api/v1/class-attendance/student/active_signs", {
headers: __assign(__assign({}, baseHeaders), { openId: openId, "If-None-Match": '"38-djBNGTNDrEJXNs9DekumVQ"', Referrer: "https://v18.teachermate.cn/wechat-pro-ssr/student/sign?openid=" + openId }),
method: "GET",
});
};
exports.signIn = function (openId, query) {
return node_fetch_1.default("https://v18.teachermate.cn/wechat-api/v1/class-attendance/student-sign-in", {
headers: __assign(__assign({}, baseHeaders), { "Content-Type": "application/json", openId: openId, Referrer: "https://v18.teachermate.cn/wechat-pro-ssr/student/sign?openid=" + openId }),
return request("https://v18.teachermate.cn/wechat-api/v1/class-attendance/student-sign-in", {
headers: __assign(__assign({}, baseHeaders), { openId: openId, Referrer: "https://v18.teachermate.cn/wechat-pro-ssr/student/sign?openid=" + openId }),
body: JSON.stringify(query),
method: "POST",
});
};
// export const tryShortenURL = async (url: string) => {
// try {
// const resp = await fetch(
// `https://v1.alapi.cn/api/url?url=${encodeURIComponent(url)}`
// );
// const json = await resp.json();
// return json.data.short_url;
// } catch (err) {
// console.log(err)
// return url;
// }
// };
var studentsRole = function (openId) {
return request("https://v18.teachermate.cn/wechat-api/v2/students/role", {
headers: __assign(__assign({}, baseHeaders), { openid: openId, Referrer: "https://v18.teachermate.cn/wechat-pro/student/archive/lists?openid=" + openId }),
method: "GET",
});
};
exports.checkInvaild = function (openId) { return __awaiter(void 0, void 0, void 0, function () {
var data;
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, studentsRole(openId)];
case 1:
data = _a.sent();
return [2 /*return*/, "message" in data || data.length === 0];
}
});
}); };
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"description": "yet another teachermate helper",
"license": "MIT",
"version": "1.2.0",
"version": "1.2.1",
"scripts": {
"start": "node ./dist/index.js",
"build": "tsc"
Expand Down

0 comments on commit 39301c1

Please sign in to comment.