This commit is contained in:
les
2019-09-11 19:12:24 +02:00
parent 93baf01a55
commit 2fe956d117
65 changed files with 762 additions and 721 deletions

View File

@@ -1,10 +1,10 @@
'use strict'
module.exports = (sequelize, DataTypes) => {
module.exports = (sequelize, DataTypes) => {
const comment = sequelize.define('comment', {
activitypub_id: {
type: DataTypes.STRING(18),
index: true,
unique: true,
unique: true
},
data: DataTypes.JSON
}, {})
@@ -12,4 +12,4 @@
comment.belongsTo(models.event)
}
return comment
};
}

View File

@@ -6,7 +6,7 @@ module.exports = (sequelize, DataTypes) => {
id: {
type: DataTypes.INTEGER,
primaryKey: true,
autoIncrement: true,
autoIncrement: true
},
title: DataTypes.STRING,
slug: DataTypes.STRING,
@@ -36,8 +36,8 @@ module.exports = (sequelize, DataTypes) => {
event.hasMany(models.comment)
}
//
event.prototype.toAP = function (username=config.admin, follower) {
//
event.prototype.toAP = function (username = config.admin, follower) {
const tags = this.tags && this.tags.map(t => '#' + t.tag).join(' ')
const content = `<b><a href='${config.baseurl}/event/${this.id}'>${this.title}</a></b><br/>
📍${this.place.name}<br/>
@@ -45,7 +45,7 @@ module.exports = (sequelize, DataTypes) => {
${this.description.length > 200 ? this.description.substr(0, 200) + '...' : this.description}<br/>
${tags} <br/>`
let attachment = []
const attachment = []
if (this.image_path) {
attachment.push({
type: 'Document',
@@ -62,19 +62,22 @@ module.exports = (sequelize, DataTypes) => {
// actor: `${config.baseurl}/federation/u/${username}`,
// url: `${config.baseurl}/federation/m/${this.id}`,
// object: {
attachment,
tag: this.tags.map(tag => ({
type: 'Hashtag',
name: '#' + tag.tag
})),
id: `${config.baseurl}/federation/m/${this.id}`,
type: 'Note',
published: this.createdAt,
attributedTo: `${config.baseurl}/federation/u/${username}`,
to: 'https://www.w3.org/ns/activitystreams#Public',
cc: follower ? follower: [],
content
}
type: 'Note',
id: `${config.baseurl}/federation/m/${this.id}`,
url: `${config.baseurl}/federation/m/${this.id}`,
attachment,
tag: this.tags.map(tag => ({
type: 'Hashtag',
name: '#' + tag.tag
})),
published: this.createdAt,
attributedTo: `${config.baseurl}/federation/u/${username}`,
to: ['https://www.w3.org/ns/activitystreams#Public'],
cc: follower || [],
content,
summary: null,
sensitive: false,
// }
}
}

View File

@@ -7,7 +7,7 @@ const consola = require('consola')
const db = {}
const sequelize = new Sequelize(config.db)
sequelize.authenticate().catch( e => {
sequelize.authenticate().catch(e => {
consola.error('Error connecting to DB: ', String(e))
process.exit(-1)
})
@@ -21,15 +21,14 @@ fs
const model = sequelize.import(path.join(__dirname, file))
db[model.name] = model
})
Object.keys(db).forEach(modelName => {
if (db[modelName].associate) {
db[modelName].associate(db)
}
})
db.sequelize = sequelize
db.Sequelize = Sequelize
module.exports = db
Object.keys(db).forEach(modelName => {
if (db[modelName].associate) {
db[modelName].associate(db)
}
})
db.sequelize = sequelize
db.Sequelize = Sequelize
module.exports = db

View File

@@ -3,7 +3,8 @@ module.exports = (sequelize, DataTypes) => {
const place = sequelize.define('place', {
name: {
type: DataTypes.STRING,
unique: true, index: true,
unique: true,
index: true,
allowNull: false
},
address: DataTypes.STRING

View File

@@ -15,4 +15,4 @@ module.exports = (sequelize, DataTypes) => {
}
return tag
};
}

View File

@@ -18,7 +18,7 @@ module.exports = (sequelize, DataTypes) => {
settings: DataTypes.JSON,
email: {
type: DataTypes.STRING,
unique: { msg: 'error.email_taken' },
unique: { msg: 'error.email_taken' },
index: true,
allowNull: false
},
@@ -46,7 +46,7 @@ module.exports = (sequelize, DataTypes) => {
}
user.prototype.comparePassword = async function (pwd) {
if (!this.password) return false
if (!this.password) { return false }
const ret = await bcrypt.compare(pwd, this.password)
return ret
}
@@ -78,4 +78,4 @@ module.exports = (sequelize, DataTypes) => {
})
return user
};
}