Skip to content

Commit 02d4496

Browse files
committed
remove * as models
1 parent 79a3a9a commit 02d4496

File tree

15 files changed

+102
-105
lines changed

15 files changed

+102
-105
lines changed

lib/app.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import {Server as WsServer} from 'ws'
2222
import config from "./config";
2323
import {logger} from "./logger";
2424
import * as response from "./response";
25-
import * as models from "./models";
25+
import {sequelize} from "./models";
2626
import * as csp from "./csp";
2727
import {Environment} from "./config/enum";
2828
import {checkAllNotesRevision} from "./services/note";
@@ -101,7 +101,7 @@ app.use(methodOverride('_method'))
101101

102102
// session store
103103
const sessionStore = new SequelizeStore({
104-
db: models.sequelize
104+
db: sequelize
105105
})
106106

107107
// use hsts to tell https users stick to this
@@ -286,7 +286,7 @@ function startListen() {
286286
}
287287

288288
// sync db then start listen
289-
models.sequelize.sync().then(function () {
289+
sequelize.sync().then(function () {
290290
// check if realtime is ready
291291
if (realtime.isReady()) {
292292
checkAllNotesRevision(function (err, notes) {

lib/auth/email/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ import passport from "passport";
33
import validator from "validator";
44
import {Strategy as LocalStrategy} from 'passport-local';
55

6-
import * as models from '../../models';
76
import config from '../../config';
7+
import {User} from '../../models';
88
import {logger} from "../../logger";
99
import {setReturnToFromReferer} from "../utils";
1010
import {urlencodedParser} from "../../utils";
@@ -19,7 +19,7 @@ passport.use(new LocalStrategy({
1919
if (!validator.isEmail(email)) return done(null, false)
2020

2121
try {
22-
const user = await models.User.findOne({
22+
const user = await User.findOne({
2323
where: {
2424
email: email
2525
}
@@ -39,7 +39,7 @@ if (config.allowEmailRegister) {
3939
if (!req.body.email || !req.body.password) return response.errorBadRequest(req, res)
4040
if (!validator.isEmail(req.body.email)) return response.errorBadRequest(req, res)
4141
try {
42-
const [user, created] = await models.User.findOrCreate({
42+
const [user, created] = await User.findOrCreate({
4343
where: {
4444
email: req.body.email
4545
},

lib/auth/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import {Router} from "express";
33
import passport from "passport";
44
import config from "../config";
55
import {logger} from "../logger";
6-
import * as models from "../models";
6+
import {User} from "../models";
77

88
const authRouter = Router()
99
export = authRouter
@@ -15,7 +15,7 @@ passport.serializeUser(function (user: any, done) {
1515
})
1616

1717
passport.deserializeUser(function (id, done) {
18-
models.User.findOne({
18+
User.findOne({
1919
where: {
2020
id: id
2121
}

lib/auth/ldap/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import passport from "passport";
33
import LDAPStrategy from "passport-ldapauth";
44

55
import config from "../../config";
6-
import * as models from "../../models";
6+
import {User} from "../../models";
77
import {logger} from "../../logger";
88
import * as response from "../../response";
99
import {setReturnToFromReferer} from "../utils";
@@ -50,7 +50,7 @@ passport.use(new LDAPStrategy({
5050
provider: 'ldap'
5151
}
5252
const stringifiedProfile = JSON.stringify(profile)
53-
models.User.findOrCreate({
53+
User.findOrCreate({
5454
where: {
5555
profileid: profile.id.toString()
5656
},

lib/auth/openid/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import passport from "passport";
33
import {Strategy as OpenIDStrategy} from "@passport-next/passport-openid";
44

55
import config from "../../config";
6-
import * as models from "../../models";
6+
import {User} from "../../models";
77
import {logger} from "../../logger";
88
import {urlencodedParser} from "../../utils";
99
import {setReturnToFromReferer} from "../utils";
@@ -17,7 +17,7 @@ passport.use(new OpenIDStrategy({
1717
profile: true
1818
}, function (openid, profile, done) {
1919
const stringifiedProfile = JSON.stringify(profile)
20-
models.User.findOrCreate({
20+
User.findOrCreate({
2121
where: {
2222
profileid: openid
2323
},

lib/auth/saml/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import passport from "passport";
44
import {Strategy as SamlStrategy} from "passport-saml";
55

66
import config from "../../config";
7-
import * as models from "../../models";
7+
import {User} from "../../models";
88
import {logger} from "../../logger";
99
import {urlencodedParser} from "../../utils";
1010

@@ -49,7 +49,7 @@ passport.use(new SamlStrategy({
4949
profile.emails.push(user.nameID)
5050
}
5151
const stringifiedProfile = JSON.stringify(profile)
52-
models.User.findOrCreate({
52+
User.findOrCreate({
5353
where: {
5454
profileid: profile.id.toString()
5555
},

lib/auth/utils.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use strict'
22

3-
import * as models from "../models";
3+
import {User} from "../models";
44
import config from "../config";
55
import {logger} from "../logger";
66

@@ -32,7 +32,7 @@ export function setReturnToFromReferer(req) {
3232

3333
export function passportGeneralCallback(accessToken, refreshToken, profile, done) {
3434
const stringifiedProfile = JSON.stringify(profile)
35-
models.User.findOrCreate({
35+
User.findOrCreate({
3636
where: {
3737
profileid: profile.id.toString()
3838
},

lib/history/index.ts

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22
// external modules
33
import LZString from '@hackmd/lz-string'
44

5-
import * as models from '../models'
5+
import {Note, User} from '../models'
66
import {logger} from '../logger'
77
import config from '../config'
88
import * as response from '../response'
99

10-
function getHistory (userid, callback) {
11-
models.User.findOne({
10+
function getHistory(userid, callback) {
11+
User.findOne({
1212
where: {
1313
id: userid
1414
}
@@ -32,8 +32,8 @@ function getHistory (userid, callback) {
3232
}
3333
try {
3434
const id = LZString.decompressFromBase64(history[i].id)
35-
if (id && models.Note.checkNoteIdValid(id)) {
36-
history[i].id = models.Note.encodeNoteId(id)
35+
if (id && Note.checkNoteIdValid(id)) {
36+
history[i].id = Note.encodeNoteId(id)
3737
}
3838
} catch (err) {
3939
// most error here comes from LZString, ignore
@@ -56,8 +56,8 @@ function getHistory (userid, callback) {
5656
})
5757
}
5858

59-
function setHistory (userid, history, callback) {
60-
models.User.update({
59+
function setHistory(userid, history, callback) {
60+
User.update({
6161
history: JSON.stringify(parseHistoryToArray(history))
6262
}, {
6363
where: {
@@ -71,15 +71,15 @@ function setHistory (userid, history, callback) {
7171
})
7272
}
7373

74-
export function updateHistory (userid, noteId, document?: string, time?: any) {
74+
export function updateHistory(userid, noteId, document?: string, time?: any) {
7575
if (userid && noteId && typeof document !== 'undefined') {
7676
getHistory(userid, function (err, history) {
7777
if (err || !history) return
7878
if (!history[noteId]) {
7979
history[noteId] = {}
8080
}
8181
const noteHistory = history[noteId]
82-
const noteInfo = models.Note.parseNoteInfo(document)
82+
const noteInfo = Note.parseNoteInfo(document)
8383
noteHistory.id = noteId
8484
noteHistory.text = noteInfo.title
8585
noteHistory.time = time || Date.now()
@@ -93,7 +93,7 @@ export function updateHistory (userid, noteId, document?: string, time?: any) {
9393
}
9494
}
9595

96-
function parseHistoryToArray (history) {
96+
function parseHistoryToArray(history) {
9797
const _history = []
9898
Object.keys(history).forEach(function (key) {
9999
const item = history[key]
@@ -102,7 +102,7 @@ function parseHistoryToArray (history) {
102102
return _history
103103
}
104104

105-
function parseHistoryToObject (history) {
105+
function parseHistoryToObject(history) {
106106
const _history = {}
107107
for (let i = 0, l = history.length; i < l; i++) {
108108
const item = history[i]
@@ -111,7 +111,7 @@ function parseHistoryToObject (history) {
111111
return _history
112112
}
113113

114-
export function historyGet (req, res) {
114+
export function historyGet(req, res) {
115115
if (req.isAuthenticated()) {
116116
getHistory(req.user.id, function (err, history) {
117117
if (err) return response.errorInternalError(req, res)
@@ -125,12 +125,14 @@ export function historyGet (req, res) {
125125
}
126126
}
127127

128-
export function historyPost (req, res) {
128+
export function historyPost(req, res) {
129129
if (req.isAuthenticated()) {
130130
const noteId = req.params.noteId
131131
if (!noteId) {
132132
if (typeof req.body.history === 'undefined') return response.errorBadRequest(req, res)
133-
if (config.debug) { logger.info('SERVER received history from [' + req.user.id + ']: ' + req.body.history) }
133+
if (config.debug) {
134+
logger.info('SERVER received history from [' + req.user.id + ']: ' + req.body.history)
135+
}
134136
let history = null
135137
try {
136138
history = JSON.parse(req.body.history)
@@ -167,7 +169,7 @@ export function historyPost (req, res) {
167169
}
168170
}
169171

170-
export function historyDelete (req, res) {
172+
export function historyDelete(req, res) {
171173
if (req.isAuthenticated()) {
172174
const noteId = req.params.noteId
173175
if (!noteId) {

lib/homepage/index.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
import * as fs from 'fs'
22
import * as path from 'path'
33
import config from '../config'
4-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
5-
// @ts-ignore
64
import {User} from '../models'
75
import {logger} from '../logger'
86
import {Request, Response} from "express";

0 commit comments

Comments
 (0)