Migrate to shortid for easier links
This commit is contained in:
parent
1c30cbf58e
commit
9e8fdcac95
6 changed files with 37 additions and 7 deletions
|
|
@ -1,8 +1,8 @@
|
|||
import { Application } from "express"
|
||||
import { PassportStatic } from "passport"
|
||||
import * as Auth from './auth'
|
||||
import shortid from 'shortid'
|
||||
import ConfigDB from '../models/config.model'
|
||||
|
||||
import * as Auth from './auth'
|
||||
|
||||
export const init = (app: Application, passport: PassportStatic) => {
|
||||
app.get('/', async (req, res) => {
|
||||
|
|
@ -15,12 +15,13 @@ export const init = (app: Application, passport: PassportStatic) => {
|
|||
try {
|
||||
const conf = new ConfigDB()
|
||||
conf.json = req.body.json
|
||||
|
||||
await conf.save()
|
||||
|
||||
if (req.isAuthenticated() && req.user) {
|
||||
req.user.configs.push({
|
||||
name: req.body.name,
|
||||
conf: conf._id
|
||||
conf: conf.shortid
|
||||
})
|
||||
}
|
||||
res.status(200).send(conf)
|
||||
|
|
@ -32,7 +33,9 @@ export const init = (app: Application, passport: PassportStatic) => {
|
|||
})
|
||||
|
||||
app.get('/configs/:id', async (req, res) => {
|
||||
const conf = await ConfigDB.findById(req.params.id)
|
||||
const conf = await ConfigDB.findOne({
|
||||
shortid: req.params.id
|
||||
})
|
||||
if (conf) {
|
||||
res.json(conf.json)
|
||||
} else {
|
||||
|
|
|
|||
Loading…
Reference in a new issue