You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Hydro/packages/hydrooj/src/model/oauth.ts

30 lines
702 B
TypeScript

4 years ago
import { Collection } from 'mongodb';
import db from '../service/db';
4 years ago
interface OauthMap {
_id: string, // source openId
uid: number, // target uid
}
const coll: Collection<OauthMap> = db.collection('oauth');
class OauthModel {
static async get(_id: string) {
const doc = await coll.findOne({ _id });
if (doc) return doc.uid;
return null;
}
4 years ago
static async set(_id: string, value: number) {
const res = await coll.findOneAndUpdate(
{ _id },
{ $set: { value } },
{ upsert: true, returnOriginal: false },
);
return res.value.uid;
}
4 years ago
}
export = OauthModel;
global.Hydro.model.oauth = OauthModel;