[refactoring] s/comment/resource
This commit is contained in:
@@ -49,8 +49,7 @@
|
|||||||
"disable": "Disable",
|
"disable": "Disable",
|
||||||
"me": "You",
|
"me": "You",
|
||||||
"password_updated": "Password updated!",
|
"password_updated": "Password updated!",
|
||||||
"username": "Username",
|
"resources": "Resources",
|
||||||
"comments": "Comments",
|
|
||||||
"activate_user": "Confirmed",
|
"activate_user": "Confirmed",
|
||||||
"displayname": "Display name",
|
"displayname": "Display name",
|
||||||
"federation": "Federation",
|
"federation": "Federation",
|
||||||
@@ -141,20 +140,20 @@
|
|||||||
"user_create_ok": "User created",
|
"user_create_ok": "User created",
|
||||||
"allow_registration_description": "Allow open registrations?",
|
"allow_registration_description": "Allow open registrations?",
|
||||||
"allow_anon_event": "Allow anon events (has to be confirmed)?",
|
"allow_anon_event": "Allow anon events (has to be confirmed)?",
|
||||||
"allow_comments": "Enable comments",
|
|
||||||
"allow_recurrent_event": "Enable recurrent events",
|
"allow_recurrent_event": "Enable recurrent events",
|
||||||
"recurrent_event_visible": "Show recurrent events by default",
|
"recurrent_event_visible": "Show recurrent events by default",
|
||||||
"federation": "Federation / ActivityPub",
|
"federation": "Federation / ActivityPub",
|
||||||
"enable_federation": "Enable federation",
|
"enable_federation": "Enable federation",
|
||||||
"enable_federation_help": "It will be possible to follow this instance from the fediverse",
|
"enable_federation_help": "It will be possible to follow this instance from the fediverse",
|
||||||
"select_instance_timezone": "Select instance timezone",
|
"select_instance_timezone": "Select instance timezone",
|
||||||
"enable_comments": "Enable comments",
|
"enable_resources": "Enable resources",
|
||||||
"enable_comments_help": "Allows you to add resources to the event from the fediverse",
|
"enable_resources_help": "Allows you to add resources to the event from the fediverse",
|
||||||
"hide_boost_bookmark": "Hides boost/bookmark numbers",
|
"hide_boost_bookmark": "Hides boost/bookmark numbers",
|
||||||
"hide_boost_bookmark_help": "Hides the small icons that show the number of boosts / bookmarks coming from the fediverse",
|
"hide_boost_bookmark_help": "Hides the small icons that show the number of boosts / bookmarks coming from the fediverse",
|
||||||
"block_instance": "Block",
|
"block": "Block",
|
||||||
"unblock_instance": "Unblock",
|
"unblock": "Unblock",
|
||||||
"user_add_help": "We will send an email to the new user with instructions to confirm the subscription and choose a password"
|
"user_add_help": "We will send an email to the new user with instructions to confirm the subscription and choose a password",
|
||||||
|
"instance_name": "Instance name"
|
||||||
},
|
},
|
||||||
"auth": {
|
"auth": {
|
||||||
"not_confirmed": "Not confirmed yet",
|
"not_confirmed": "Not confirmed yet",
|
||||||
|
|||||||
@@ -65,7 +65,8 @@
|
|||||||
"feed_url_copied": "Feed url copiato, incollalo nel tuo feed reader",
|
"feed_url_copied": "Feed url copiato, incollalo nel tuo feed reader",
|
||||||
"follow_me_title": "Segui gli aggiornamenti dal fediverso",
|
"follow_me_title": "Segui gli aggiornamenti dal fediverso",
|
||||||
"follow": "Segui",
|
"follow": "Segui",
|
||||||
"resources": "nessuna risorsa|una risorsa|{n} risorse",
|
"n_resources": "nessuna risorsa|una risorsa|{n} risorse",
|
||||||
|
"resources": "Risorse",
|
||||||
"moderation": "Moderazione"
|
"moderation": "Moderazione"
|
||||||
},
|
},
|
||||||
"login": {
|
"login": {
|
||||||
@@ -141,27 +142,29 @@
|
|||||||
"user_create_ok": "Utente creato",
|
"user_create_ok": "Utente creato",
|
||||||
"allow_registration_description": "Vuoi abilitare la registrazione?",
|
"allow_registration_description": "Vuoi abilitare la registrazione?",
|
||||||
"allow_anon_event": "Si possono inserire eventi anonimi (previa conferma)?",
|
"allow_anon_event": "Si possono inserire eventi anonimi (previa conferma)?",
|
||||||
"allow_comments": "Abilita commenti",
|
|
||||||
"allow_recurrent_event": "Abilita eventi fissi",
|
"allow_recurrent_event": "Abilita eventi fissi",
|
||||||
"recurrent_event_visible": "Appuntamenti fissi visibili di default",
|
"recurrent_event_visible": "Appuntamenti fissi visibili di default",
|
||||||
"federation": "Federazione / ActivityPub",
|
"federation": "Federazione / ActivityPub",
|
||||||
"enable_federation": "Abilita la federazione!",
|
"enable_federation": "Abilita la federazione!",
|
||||||
"enable_federation_help": "Sarà possibile seguire questa istanza dal fediverso",
|
"enable_federation_help": "Sarà possibile seguire questa istanza dal fediverso",
|
||||||
"select_instance_timezone": "Seleziona la timezone",
|
"select_instance_timezone": "Seleziona la timezone",
|
||||||
"enable_comments": "Abilita commenti",
|
"enable_resources": "Abilita risorse",
|
||||||
"enable_comments_help": "Permette di aggiungere risorse all'evento dal fediverso",
|
"enable_resources_help": "Permette di aggiungere risorse all'evento dal fediverso",
|
||||||
"hide_boost_bookmark": "Nasconde numero condivisioni/segnalibri",
|
"hide_boost_bookmark": "Nasconde numero condivisioni/segnalibri",
|
||||||
"hide_boost_bookmark_help": "Nasconde le piccole icone che mostrano il numero di boost/bookmark in arrivo dal fediverso",
|
"hide_boost_bookmark_help": "Nasconde le piccole icone che mostrano il numero di boost/bookmark in arrivo dal fediverso",
|
||||||
"block": "Blocca",
|
"block": "Blocca",
|
||||||
"unblock": "Sblocca",
|
"unblock": "Sblocca",
|
||||||
"user_add_help": "Manderemo una email al nuovo utente con le istruzioni per confermare l'iscrizione e scegliere una password",
|
"user_add_help": "Manderemo una email al nuovo utente con le istruzioni per confermare l'iscrizione e scegliere una password",
|
||||||
"comments": "Risorse",
|
"resources": "Risorse",
|
||||||
"hide_resource": "Nascondi risorsa",
|
"hide_resource": "Nascondi risorsa",
|
||||||
"show_resource": "Mostra risorsa",
|
"show_resource": "Mostra risorsa",
|
||||||
"remove_resource": "Elimina risorsa",
|
"remove_resource": "Elimina risorsa",
|
||||||
"remove_resource_confirm": "Sicura di voler eliminare questa risorsa?",
|
"remove_resource_confirm": "Sicura di voler eliminare questa risorsa?",
|
||||||
"block_user": "Blocca questo utente",
|
"block_user": "Blocca questo utente",
|
||||||
"user_blocked": "L'utente {user} non potrà più aggiungere risorse"
|
"user_blocked": "L'utente {user} non potrà più aggiungere risorse",
|
||||||
|
"filter_instances": "Filtra istanze",
|
||||||
|
"filter_users": "Filtra utenti",
|
||||||
|
"instance_name": "Nome istanza"
|
||||||
},
|
},
|
||||||
"auth": {
|
"auth": {
|
||||||
"not_confirmed": "Non abbiamo ancora confermato questa mail...",
|
"not_confirmed": "Non abbiamo ancora confermato questa mail...",
|
||||||
|
|||||||
@@ -50,7 +50,7 @@
|
|||||||
template(slot='label')
|
template(slot='label')
|
||||||
v-icon(name='network-wired')
|
v-icon(name='network-wired')
|
||||||
span.ml-1 {{$t('common.federation')}}
|
span.ml-1 {{$t('common.federation')}}
|
||||||
Federation(:instances='instances')
|
Federation
|
||||||
|
|
||||||
</template>
|
</template>
|
||||||
<script>
|
<script>
|
||||||
@@ -67,7 +67,6 @@ export default {
|
|||||||
middleware: ['auth'],
|
middleware: ['auth'],
|
||||||
data () {
|
data () {
|
||||||
return {
|
return {
|
||||||
instances: [],
|
|
||||||
perPage: 10,
|
perPage: 10,
|
||||||
eventPage: 1,
|
eventPage: 1,
|
||||||
description: '',
|
description: '',
|
||||||
@@ -84,8 +83,7 @@ export default {
|
|||||||
try {
|
try {
|
||||||
const users = await $axios.$get('/users')
|
const users = await $axios.$get('/users')
|
||||||
const events = await $axios.$get('/event/unconfirmed')
|
const events = await $axios.$get('/event/unconfirmed')
|
||||||
const instances = await $axios.$get('/instances')
|
return { users, events }
|
||||||
return { users, events, instances }
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error(e)
|
console.error(e)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -58,32 +58,32 @@
|
|||||||
a.el-button.el-button--success.el-button--mini.is-plain(role='button' plain size='mini' type='success'
|
a.el-button.el-button--success.el-button--mini.is-plain(role='button' plain size='mini' type='success'
|
||||||
:href='`${settings.baseurl}/api/event/${event.id}.ics`') <i class='el-icon-date'></i> {{$t('common.add_to_calendar')}}
|
:href='`${settings.baseurl}/api/event/${event.id}.ics`') <i class='el-icon-date'></i> {{$t('common.add_to_calendar')}}
|
||||||
|
|
||||||
//- comments from fediverse
|
//- resources from fediverse
|
||||||
#comments.mt-1(v-if='settings.enable_federation')
|
#resources.mt-1(v-if='settings.enable_federation')
|
||||||
div.float-right(v-if='!settings.disable_gamification')
|
div.float-right(v-if='!settings.hide_boosts')
|
||||||
small.mr-3 🔖 {{event.likes.length}}
|
small.mr-3 🔖 {{event.likes.length}}
|
||||||
small ✊ {{event.boost.length}}<br/>
|
small ✊ {{event.boost.length}}<br/>
|
||||||
|
|
||||||
strong(v-if='settings.enable_comments') {{$tc('common.resources', event.comments.length)}} -
|
strong(v-if='settings.enable_resources') {{$tc('common.resources', event.resources.length)}} -
|
||||||
small {{$t('event.interact_with_me_at')}}
|
small {{$t('event.interact_with_me_at')}}
|
||||||
el-button(type='text' size='mini' @click='showFollowMe=true') @{{fedi_user}}@{{settings.baseurl|url2host}}
|
el-button(type='text' size='mini' @click='showFollowMe=true') @{{settings.instance_name}}@{{settings.baseurl|url2host}}
|
||||||
|
|
||||||
el-dialog.followDialog(:visible.sync='showFollowMe')
|
el-dialog.followDialog(:visible.sync='showFollowMe')
|
||||||
h4(slot='title') {{$t('common.follow_me_title')}}
|
h4(slot='title') {{$t('common.follow_me_title')}}
|
||||||
FollowMe
|
FollowMe
|
||||||
|
|
||||||
.card-header(v-if='settings.enable_comments' v-for='comment in event.comments' :key='comment.id' :class='{disabled: comment.hidden}')
|
.card-header(v-if='settings.enable_resources' v-for='resource in event.resources' :key='resource.id' :class='{disabled: resource.hidden}')
|
||||||
a.float-right(:href='comment.data.url')
|
a.float-right(:href='resource.data.url')
|
||||||
small {{comment.data.published|datetime}}
|
small {{resource.data.published|datetime}}
|
||||||
div.mt-1(v-html='comment_filter(comment.data.content)')
|
div.mt-1(v-html='resource_filter(resource.data.content)')
|
||||||
img(v-for='img in comment.data.media_attachments' :src='img.url')
|
img(v-for='img in resource.data.media_attachments' :src='img.url')
|
||||||
el-dropdown
|
el-dropdown
|
||||||
el-button(type="primary" icon="el-icon-arrow-down" size='mini') {{$t('common.moderation')}}
|
el-button(type="primary" icon="el-icon-arrow-down" size='mini') {{$t('common.moderation')}}
|
||||||
el-dropdown-menu(slot='dropdown')
|
el-dropdown-menu(slot='dropdown')
|
||||||
el-dropdown-item(v-if='!comment.hidden' icon='el-icon-remove' @click.native='hideComment(comment, true)') {{$t('admin.hide_resource')}}
|
el-dropdown-item(v-if='!resource.hidden' icon='el-icon-remove' @click.native='hideResource(resource, true)') {{$t('admin.hide_resource')}}
|
||||||
el-dropdown-item(v-else icon='el-icon-success' @click.native='hideComment(comment, false)') {{$t('admin.show_resource')}}
|
el-dropdown-item(v-else icon='el-icon-success' @click.native='hideResource(resource, false)') {{$t('admin.show_resource')}}
|
||||||
el-dropdown-item(icon='el-icon-delete' @click.native='removeComment(comment)') {{$t('admin.remove_resource')}}
|
el-dropdown-item(icon='el-icon-delete' @click.native='removeResource(resource)') {{$t('admin.remove_resource')}}
|
||||||
el-dropdown-item(icon='el-icon-lock' @click.native='blockUser(comment)') {{$t('admin.block_user')}}
|
el-dropdown-item(icon='el-icon-lock' @click.native='blockUser(resource)') {{$t('admin.block_user')}}
|
||||||
|
|
||||||
</template>
|
</template>
|
||||||
<script>
|
<script>
|
||||||
@@ -201,10 +201,6 @@ export default {
|
|||||||
computed: {
|
computed: {
|
||||||
...mapGetters(['filteredEvents']),
|
...mapGetters(['filteredEvents']),
|
||||||
...mapState(['settings']),
|
...mapState(['settings']),
|
||||||
fedi_user() {
|
|
||||||
// TODO:
|
|
||||||
return this.settings.fedi_admin
|
|
||||||
},
|
|
||||||
next() {
|
next() {
|
||||||
let found = false
|
let found = false
|
||||||
const event = this.filteredEvents.find(e => {
|
const event = this.filteredEvents.find(e => {
|
||||||
@@ -262,29 +258,29 @@ export default {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
async hideComment (comment, hidden) {
|
async hideResource (resource, hidden) {
|
||||||
await this.$axios.$post(`/comments/${comment.id}`, { hidden })
|
await this.$axios.$put(`/resources/${resource.id}`, { hidden })
|
||||||
comment.hidden = hidden
|
resource.hidden = hidden
|
||||||
},
|
},
|
||||||
async blockUser (comment) {
|
async blockUser (resource) {
|
||||||
await this.$axios.post('/instances/toggle_user_block', { user_id: comment.fedUserApId })
|
await this.$axios.post('/instances/toggle_user_block', { user_id: resource.apUserApId })
|
||||||
Message({ message: this.$t('admin.user_blocked', {user: comment.fedUserApId}), type: 'success', showClose: true })
|
Message({ message: this.$t('admin.user_blocked', {user: resource.apUserApId}), type: 'success', showClose: true })
|
||||||
},
|
},
|
||||||
async removeComment (comment) {
|
async removeResource (resource) {
|
||||||
MessageBox.confirm(this.$t('admin.remove_resource_confirm'),
|
MessageBox.confirm(this.$t('admin.remove_resource_confirm'),
|
||||||
this.$t('common.confirm'), {
|
this.$t('common.confirm'), {
|
||||||
confirmButtonText: this.$t('common.ok'),
|
confirmButtonText: this.$t('common.ok'),
|
||||||
cancelButtonText: this.$t('common.cancel'),
|
cancelButtonText: this.$t('common.cancel'),
|
||||||
type: 'error'
|
type: 'error'
|
||||||
}).then(async () => {
|
}).then(async () => {
|
||||||
await this.$axios.delete(`/comments/${comment.id}`)
|
await this.$axios.delete(`/resources/${resource.id}`)
|
||||||
this.event.comments = this.event.comments.filter(c => c.id !== comment.id)
|
this.event.resources = this.event.resources.filter(r => r.id !== resources.id)
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
copyLink() {
|
copyLink() {
|
||||||
Message({ message: this.$t('common.copied'), type: 'success', showClose: true })
|
Message({ message: this.$t('common.copied'), type: 'success', showClose: true })
|
||||||
},
|
},
|
||||||
comment_filter(value) {
|
resource_filter(value) {
|
||||||
return value.replace(
|
return value.replace(
|
||||||
/<a.*href="([^">]+).*>(?:.(?!<\/a>))*.<\/a>/,
|
/<a.*href="([^">]+).*>(?:.(?!<\/a>))*.<\/a>/,
|
||||||
(orig, url) => {
|
(orig, url) => {
|
||||||
@@ -379,7 +375,7 @@ export default {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#comments {
|
#resources {
|
||||||
img {
|
img {
|
||||||
max-width: 100%;
|
max-width: 100%;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import Vue from 'vue'
|
import Vue from 'vue'
|
||||||
import moment from 'moment-timezone'
|
import moment from 'moment-timezone'
|
||||||
|
import url from 'url'
|
||||||
|
|
||||||
export default ({ app, store }) => {
|
export default ({ app, store }) => {
|
||||||
// set timezone to instance_timezone!!
|
// set timezone to instance_timezone!!
|
||||||
@@ -10,7 +11,6 @@ export default ({ app, store }) => {
|
|||||||
// replace links with anchors
|
// replace links with anchors
|
||||||
// TODO: remove fb tracking id
|
// TODO: remove fb tracking id
|
||||||
Vue.filter('linkify', value => value.replace(/(https?:\/\/([^\s]+))/g, '<a href="$1">$2</a>'))
|
Vue.filter('linkify', value => value.replace(/(https?:\/\/([^\s]+))/g, '<a href="$1">$2</a>'))
|
||||||
|
|
||||||
Vue.filter('url2host', url => url.match(/^https?:\/\/(.[^/:]+)/i)[1])
|
Vue.filter('url2host', url => url.match(/^https?:\/\/(.[^/:]+)/i)[1])
|
||||||
Vue.filter('datetime', value => moment(value).locale(store.state.locale).format('ddd, D MMMM HH:mm'))
|
Vue.filter('datetime', value => moment(value).locale(store.state.locale).format('ddd, D MMMM HH:mm'))
|
||||||
|
|
||||||
|
|||||||
@@ -2,29 +2,28 @@ const crypto = require('crypto')
|
|||||||
const moment = require('moment-timezone')
|
const moment = require('moment-timezone')
|
||||||
const { Op } = require('sequelize')
|
const { Op } = require('sequelize')
|
||||||
const lodash = require('lodash')
|
const lodash = require('lodash')
|
||||||
const { event: Event, comment: Comment, tag: Tag, place: Place,
|
const { event: Event, resource: Resource, tag: Tag, place: Place, notification: Notification } = require('../models')
|
||||||
user: User, notification: Notification } = require('../models')
|
|
||||||
const Sequelize = require('sequelize')
|
const Sequelize = require('sequelize')
|
||||||
const exportController = require('./export')
|
const exportController = require('./export')
|
||||||
const debug = require('debug')('controller:event')
|
const debug = require('debug')('controller:event')
|
||||||
|
|
||||||
const eventController = {
|
const eventController = {
|
||||||
|
|
||||||
/** add a comment to event
|
/** add a resource to event
|
||||||
* @todo not used anywhere, should we use with webmention?
|
* @todo not used anywhere, should we use with webmention?
|
||||||
* @todo should we use this for roply coming from fediverse?
|
* @todo should we use this for roply coming from fediverse?
|
||||||
*/
|
*/
|
||||||
async addComment (req, res) {
|
// async addComment (req, res) {
|
||||||
// comments could be added to an event or to another comment
|
// // comments could be added to an event or to another comment
|
||||||
let event = await Event.findOne({ where: { activitypub_id: { [Op.eq]: req.body.id } } })
|
// let event = await Event.findOne({ where: { activitypub_id: { [Op.eq]: req.body.id } } })
|
||||||
if (!event) {
|
// if (!event) {
|
||||||
const comment = await Comment.findOne({ where: { activitypub_id: { [Op.eq]: req.body.id } }, include: Event })
|
// const comment = await Resource.findOne({ where: { activitypub_id: { [Op.eq]: req.body.id } }, include: Event })
|
||||||
event = comment.event
|
// event = comment.event
|
||||||
}
|
// }
|
||||||
const comment = new Comment(req.body)
|
// const comment = new Comment(req.body)
|
||||||
event.addComment(comment)
|
// event.addComment(comment)
|
||||||
res.json(comment)
|
// res.json(comment)
|
||||||
},
|
// },
|
||||||
|
|
||||||
async getMeta (req, res) {
|
async getMeta (req, res) {
|
||||||
const places = await Place.findAll({
|
const places = await Place.findAll({
|
||||||
@@ -94,11 +93,10 @@ const eventController = {
|
|||||||
},
|
},
|
||||||
include: [
|
include: [
|
||||||
{ model: Tag, attributes: ['tag', 'weigth'], through: { attributes: [] } },
|
{ model: Tag, attributes: ['tag', 'weigth'], through: { attributes: [] } },
|
||||||
{ model: User, attributes: ['username'] },
|
|
||||||
{ model: Place, attributes: ['name', 'address'] },
|
{ model: Place, attributes: ['name', 'address'] },
|
||||||
{ model: Comment, where: !is_admin && { hidden: false }, required: false }
|
{ model: Resource, where: !is_admin && { hidden: false }, required: false }
|
||||||
],
|
],
|
||||||
order: [ [Comment, 'id', 'DESC'] ]
|
order: [ [Resource, 'id', 'DESC'] ]
|
||||||
})
|
})
|
||||||
|
|
||||||
if (event && (event.is_visible || is_admin)) {
|
if (event && (event.is_visible || is_admin)) {
|
||||||
@@ -230,12 +228,11 @@ const eventController = {
|
|||||||
attributes: { exclude: [ 'createdAt', 'updatedAt', 'placeId' ] },
|
attributes: { exclude: [ 'createdAt', 'updatedAt', 'placeId' ] },
|
||||||
order: [[Tag, 'weigth', 'DESC']],
|
order: [[Tag, 'weigth', 'DESC']],
|
||||||
include: [
|
include: [
|
||||||
{ model: Comment, required: false, attributes: ['id'] },
|
{ model: Resource, required: false, attributes: ['id'] },
|
||||||
{ model: Tag, required: false },
|
{ model: Tag, required: false },
|
||||||
{ model: Place, required: false, attributes: ['id', 'name', 'address'] }
|
{ model: Place, required: false, attributes: ['id', 'name', 'address'] }
|
||||||
]
|
]
|
||||||
})
|
})
|
||||||
|
|
||||||
events = events.map(e => e.get()).map(e => {
|
events = events.map(e => e.get()).map(e => {
|
||||||
e.tags = e.tags.map(t => t.tag)
|
e.tags = e.tags.map(t => t.tag)
|
||||||
return e
|
return e
|
||||||
|
|||||||
30
server/api/controller/resource.js
Normal file
30
server/api/controller/resource.js
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
const { resource: Resource } = require('../models')
|
||||||
|
|
||||||
|
const resourceController = {
|
||||||
|
async hide (req, res) {
|
||||||
|
const resource_id = req.params.resource_id
|
||||||
|
const hidden = req.body.hidden
|
||||||
|
const resource = await Resource.findByPk(resource_id)
|
||||||
|
await resource.update({ hidden })
|
||||||
|
res.json(resource)
|
||||||
|
},
|
||||||
|
|
||||||
|
async remove (req, res) {
|
||||||
|
const resource_id = req.params.resource_id
|
||||||
|
const resource = await Resource.findByPk(resource_id)
|
||||||
|
await resource.destroy()
|
||||||
|
res.sendStatus(200)
|
||||||
|
},
|
||||||
|
|
||||||
|
async getAll (req, res) {
|
||||||
|
const limit = req.body.limit || 100
|
||||||
|
// const where = {}
|
||||||
|
// if (req.params.instanceId) {
|
||||||
|
// where =
|
||||||
|
//
|
||||||
|
const resources = await Resource.findAll({ limit })
|
||||||
|
res.json(resources)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = resourceController
|
||||||
@@ -8,8 +8,9 @@ const eventController = require('./controller/event')
|
|||||||
const exportController = require('./controller/export')
|
const exportController = require('./controller/export')
|
||||||
const userController = require('./controller/user')
|
const userController = require('./controller/user')
|
||||||
const settingsController = require('./controller/settings')
|
const settingsController = require('./controller/settings')
|
||||||
const instancesController = require('./controller/instances')
|
const instanceController = require('./controller/instance')
|
||||||
const fedUserController = require('./controller/fed_user')
|
const apUserController = require('./controller/ap_user')
|
||||||
|
const resourceController = require('./controller/resource')
|
||||||
|
|
||||||
const storage = require('./storage')
|
const storage = require('./storage')
|
||||||
const upload = multer({ storage })
|
const upload = multer({ storage })
|
||||||
@@ -84,12 +85,13 @@ api.get('/export/:type', exportController.export)
|
|||||||
// get events in this range
|
// get events in this range
|
||||||
api.get('/event/:month/:year', eventController.getAll)
|
api.get('/event/:month/:year', eventController.getAll)
|
||||||
|
|
||||||
api.get('/instances', isAdmin, instancesController.getAll)
|
api.get('/instances', isAdmin, instanceController.getAll)
|
||||||
api.get('/instances/:instance_domain', isAdmin, instancesController.get)
|
api.get('/instances/:instance_domain', isAdmin, instanceController.get)
|
||||||
api.post('/instances/toggle_block', isAdmin, instancesController.toggleBlock)
|
api.post('/instances/toggle_block', isAdmin, instanceController.toggleBlock)
|
||||||
api.post('/instances/toggle_user_block', isAdmin, fedUserController.toggleBlock)
|
api.post('/instances/toggle_user_block', isAdmin, apUserController.toggleBlock)
|
||||||
api.post('/comments/:comment_id', isAdmin, fedUserController.hideComment)
|
api.put('/resources/:resource_id', isAdmin, resourceController.hide)
|
||||||
api.delete('/comments/:comment_id', isAdmin, fedUserController.removeComment)
|
api.delete('/resources/:resource_id', isAdmin, resourceController.remove)
|
||||||
|
api.get('/resources', isAdmin, resourceController.getAll)
|
||||||
|
|
||||||
// Handle 404
|
// Handle 404
|
||||||
api.use((req, res) => {
|
api.use((req, res) => {
|
||||||
|
|||||||
@@ -1,26 +0,0 @@
|
|||||||
'use strict'
|
|
||||||
module.exports = (sequelize, DataTypes) => {
|
|
||||||
const comment = sequelize.define('comment', {
|
|
||||||
activitypub_id: {
|
|
||||||
type: DataTypes.STRING,
|
|
||||||
index: true,
|
|
||||||
unique: true
|
|
||||||
},
|
|
||||||
hidden: DataTypes.BOOLEAN,
|
|
||||||
fedUserApId: {
|
|
||||||
type: DataTypes.STRING,
|
|
||||||
references: {
|
|
||||||
model: 'fed_users',
|
|
||||||
key: 'ap_id'
|
|
||||||
},
|
|
||||||
onUpdate: 'CASCADE',
|
|
||||||
onDelete: 'CASCADE'
|
|
||||||
},
|
|
||||||
data: DataTypes.JSON
|
|
||||||
}, {})
|
|
||||||
comment.associate = function (models) {
|
|
||||||
comment.belongsTo(models.event)
|
|
||||||
comment.belongsTo(models.fed_users)
|
|
||||||
}
|
|
||||||
return comment
|
|
||||||
}
|
|
||||||
@@ -2,7 +2,7 @@ const config = require('config')
|
|||||||
const moment = require('moment')
|
const moment = require('moment')
|
||||||
|
|
||||||
module.exports = (sequelize, DataTypes) => {
|
module.exports = (sequelize, DataTypes) => {
|
||||||
const event = sequelize.define('event', {
|
const Event = sequelize.define('event', {
|
||||||
id: {
|
id: {
|
||||||
allowNull: false,
|
allowNull: false,
|
||||||
type: DataTypes.INTEGER,
|
type: DataTypes.INTEGER,
|
||||||
@@ -29,15 +29,15 @@ module.exports = (sequelize, DataTypes) => {
|
|||||||
boost: { type: DataTypes.JSON, defaultValue: [] }
|
boost: { type: DataTypes.JSON, defaultValue: [] }
|
||||||
}, {})
|
}, {})
|
||||||
|
|
||||||
event.associate = function (models) {
|
Event.associate = function (models) {
|
||||||
event.belongsTo(models.place)
|
Event.belongsTo(models.place)
|
||||||
event.belongsTo(models.user)
|
Event.belongsTo(models.user)
|
||||||
event.belongsToMany(models.tag, { through: 'event_tags' })
|
Event.belongsToMany(models.tag, { through: 'event_tags' })
|
||||||
event.belongsToMany(models.notification, { through: 'event_notification' })
|
Event.belongsToMany(models.notification, { through: 'event_notification' })
|
||||||
event.hasMany(models.comment)
|
Event.hasMany(models.resource)
|
||||||
}
|
}
|
||||||
|
|
||||||
event.prototype.toAP = function (username, follower = []) {
|
Event.prototype.toNoteAP = function (username, follower = []) {
|
||||||
const tags = this.tags && this.tags.map(t => t.tag.replace(/[ #]/g, ' '))
|
const tags = this.tags && this.tags.map(t => t.tag.replace(/[ #]/g, ' '))
|
||||||
const tag_links = tags.map(t => {
|
const tag_links = tags.map(t => {
|
||||||
return `<a href='/tags/${t}' class='mention hashtag status-link' rel='tag'><span>#${t}</span></a>`
|
return `<a href='/tags/${t}' class='mention hashtag status-link' rel='tag'><span>#${t}</span></a>`
|
||||||
@@ -82,5 +82,5 @@ module.exports = (sequelize, DataTypes) => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return event
|
return Event
|
||||||
}
|
}
|
||||||
|
|||||||
20
server/api/models/resource.js
Normal file
20
server/api/models/resource.js
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
module.exports = (sequelize, DataTypes) => {
|
||||||
|
|
||||||
|
const Resource = sequelize.define('resource', {
|
||||||
|
activitypub_id: {
|
||||||
|
type: DataTypes.STRING,
|
||||||
|
index: true,
|
||||||
|
unique: true
|
||||||
|
},
|
||||||
|
hidden: DataTypes.BOOLEAN,
|
||||||
|
data: DataTypes.JSON
|
||||||
|
}, {})
|
||||||
|
|
||||||
|
Resource.associate = function (models) {
|
||||||
|
// Resource.belongsTo(models.instance)
|
||||||
|
Resource.belongsTo(models.event)
|
||||||
|
Resource.belongsTo(models.ap_user)
|
||||||
|
}
|
||||||
|
|
||||||
|
return Resource
|
||||||
|
}
|
||||||
@@ -1,45 +0,0 @@
|
|||||||
const { event: Event, comment: Comment } = require('../api/models')
|
|
||||||
const debug = require('debug')('fediverse:comment')
|
|
||||||
|
|
||||||
module.exports = {
|
|
||||||
async create (req, res) {
|
|
||||||
const body = req.body
|
|
||||||
// search for related event
|
|
||||||
const inReplyTo = body.object.inReplyTo
|
|
||||||
const match = inReplyTo.match('.*/federation/m/(.*)')
|
|
||||||
if (!match || match.length < 2) {
|
|
||||||
debug('Comment not found %s', inReplyTo)
|
|
||||||
return res.status(404).send('Event not found!')
|
|
||||||
}
|
|
||||||
let event = await Event.findByPk(Number(match[1]))
|
|
||||||
|
|
||||||
debug('comment coming for %s', inReplyTo)
|
|
||||||
if (!event) {
|
|
||||||
// in reply to another comment...
|
|
||||||
const comment = await Comment.findOne({ where: { activitypub_id: inReplyTo }, include: [Event] })
|
|
||||||
if (!comment) { return res.status(404).send('Not found') }
|
|
||||||
event = comment.event
|
|
||||||
}
|
|
||||||
debug('comment from %s to "%s"', req.body.actor, event.title)
|
|
||||||
|
|
||||||
await Comment.create({
|
|
||||||
activitypub_id: body.object.id,
|
|
||||||
fedUserApId: req.body.actor,
|
|
||||||
data: body.object,
|
|
||||||
eventId: event.id
|
|
||||||
})
|
|
||||||
|
|
||||||
res.sendStatus(201)
|
|
||||||
},
|
|
||||||
|
|
||||||
async remove (req, res) {
|
|
||||||
const comment = await Comment.findOne({ where: { activitypub_id: req.body.object.id } })
|
|
||||||
if (!comment) {
|
|
||||||
debug('Comment %s not found', req.body.object.id)
|
|
||||||
return res.status(404).send('Not found')
|
|
||||||
}
|
|
||||||
await comment.destroy()
|
|
||||||
debug('Comment %s removed!', req.body.object.id)
|
|
||||||
return res.sendStatus(201)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,6 +1,5 @@
|
|||||||
const config = require('config')
|
const config = require('config')
|
||||||
const Helpers = require('./helpers')
|
const Helpers = require('./helpers')
|
||||||
const { user: User, fed_users: FedUsers } = require('../api/models')
|
|
||||||
const crypto = require('crypto')
|
const crypto = require('crypto')
|
||||||
const debug = require('debug')('federation:follows')
|
const debug = require('debug')('federation:follows')
|
||||||
|
|
||||||
|
|||||||
@@ -3,9 +3,9 @@ const router = express.Router()
|
|||||||
const cors = require('cors')
|
const cors = require('cors')
|
||||||
const Follows = require('./follows')
|
const Follows = require('./follows')
|
||||||
const Users = require('./users')
|
const Users = require('./users')
|
||||||
const { event: Event, user: User, tag: Tag, place: Place } = require('../api/models')
|
const { Event, User, Tag, Place } = require('../api/models')
|
||||||
const settingsController = require('../api/controller/settings')
|
const settingsController = require('../api/controller/settings')
|
||||||
const Comments = require('./comments')
|
const Resources = require('./resources')
|
||||||
const Helpers = require('./helpers')
|
const Helpers = require('./helpers')
|
||||||
const Ego = require('./ego')
|
const Ego = require('./ego')
|
||||||
const debug = require('debug')('federation')
|
const debug = require('debug')('federation')
|
||||||
@@ -65,12 +65,12 @@ router.post('/u/:name/inbox', Helpers.verifySignature, async (req, res) => {
|
|||||||
Ego.bookmark(req, res)
|
Ego.bookmark(req, res)
|
||||||
break
|
break
|
||||||
case 'Delete':
|
case 'Delete':
|
||||||
await Comments.remove(req, res)
|
await Resources.remove(req, res)
|
||||||
break
|
break
|
||||||
case 'Create':
|
case 'Create':
|
||||||
// this is a reply
|
// this is a reply
|
||||||
if (b.object.type === 'Note' && b.object.inReplyTo) {
|
if (b.object.type === 'Note' && b.object.inReplyTo) {
|
||||||
await Comments.create(req, res)
|
await Resources.create(req, res)
|
||||||
} else {
|
} else {
|
||||||
debug('Create with unsupported Object or not a reply => %s ', b.object.type)
|
debug('Create with unsupported Object or not a reply => %s ', b.object.type)
|
||||||
}
|
}
|
||||||
|
|||||||
52
server/federation/resources.js
Normal file
52
server/federation/resources.js
Normal file
@@ -0,0 +1,52 @@
|
|||||||
|
const { event: Event, resource: Resource } = require('../api/models')
|
||||||
|
const debug = require('debug')('fediverse:resource')
|
||||||
|
const sanitize = require('sanitize-html')
|
||||||
|
module.exports = {
|
||||||
|
|
||||||
|
async create (req, res) {
|
||||||
|
const body = req.body
|
||||||
|
|
||||||
|
// search for related event
|
||||||
|
const inReplyTo = body.object.inReplyTo
|
||||||
|
const match = inReplyTo.match('.*/federation/m/(.*)')
|
||||||
|
if (!match || match.length < 2) {
|
||||||
|
debug('Resource not found %s', inReplyTo)
|
||||||
|
return res.status(404).send('Event not found!')
|
||||||
|
}
|
||||||
|
|
||||||
|
let event = await Event.findByPk(Number(match[1]))
|
||||||
|
debug('Resource coming for %s', inReplyTo)
|
||||||
|
if (!event) {
|
||||||
|
// in reply to another resource...
|
||||||
|
const resource = await Resource.findOne({ where: { activitypub_id: inReplyTo }, include: [Event] })
|
||||||
|
if (!resource) { return res.status(404).send('Not found') }
|
||||||
|
event = resource.event
|
||||||
|
}
|
||||||
|
debug('resource from %s to "%s"', req.body.actor, event.title)
|
||||||
|
|
||||||
|
// clean resource
|
||||||
|
body.object.content = sanitize(body.object.content, {
|
||||||
|
nonTextTags: ['span', 'style', 'script', 'textarea', 'noscript']
|
||||||
|
})
|
||||||
|
|
||||||
|
await Resource.create({
|
||||||
|
activitypub_id: body.object.id,
|
||||||
|
apUserApId: req.body.actor,
|
||||||
|
data: body.object,
|
||||||
|
eventId: event.id
|
||||||
|
})
|
||||||
|
|
||||||
|
res.sendStatus(201)
|
||||||
|
},
|
||||||
|
|
||||||
|
async remove (req, res) {
|
||||||
|
const resource = await Resource.findOne({ where: { activitypub_id: req.body.object.id } })
|
||||||
|
if (!resource) {
|
||||||
|
debug('Comment %s not found', req.body.object.id)
|
||||||
|
return res.status(404).send('Not found')
|
||||||
|
}
|
||||||
|
await resource.destroy()
|
||||||
|
debug('Comment %s removed!', req.body.object.id)
|
||||||
|
return res.sendStatus(201)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,14 +1,13 @@
|
|||||||
const { user: User, event: Event, place: Place, tag: Tag, fed_users: FedUsers } = require('../api/models')
|
const { User, Event, Place, Tag, APUser } = require('../api/models')
|
||||||
const config = require('config')
|
const config = require('config')
|
||||||
const get = require('lodash/get')
|
|
||||||
const debug = require('debug')('fediverse:user')
|
const debug = require('debug')('fediverse:user')
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
async get (req, res) {
|
get (req, res) {
|
||||||
const name = req.params.name
|
const name = req.params.name
|
||||||
if (!name) { return res.status(400).send('Bad request.') }
|
if (!name) { return res.status(400).send('Bad request.') }
|
||||||
const user = await User.findOne({ where: { username: name } })
|
// const user = await User.findOne({ where: { username: name } })
|
||||||
if (!user) { return res.status(404).send(`No record found for ${name}`) }
|
if (name !== req.settings.instance_name) { return res.status(404).send(`No record found for ${name}`) }
|
||||||
const ret = {
|
const ret = {
|
||||||
'@context': [
|
'@context': [
|
||||||
'https://www.w3.org/ns/activitystreams',
|
'https://www.w3.org/ns/activitystreams',
|
||||||
|
|||||||
25
server/migrations/20191127234917-rename_comment_resource.js
Normal file
25
server/migrations/20191127234917-rename_comment_resource.js
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
up: (queryInterface, Sequelize) => {
|
||||||
|
/*
|
||||||
|
Add altering commands here.
|
||||||
|
Return a promise to correctly handle asynchronicity.
|
||||||
|
|
||||||
|
Example:
|
||||||
|
return queryInterface.createTable('users', { id: Sequelize.INTEGER });
|
||||||
|
*/
|
||||||
|
return queryInterface.renameTable('comments', 'resources')
|
||||||
|
},
|
||||||
|
|
||||||
|
down: (queryInterface, Sequelize) => {
|
||||||
|
/*
|
||||||
|
Add reverting commands here.
|
||||||
|
Return a promise to correctly handle asynchronicity.
|
||||||
|
|
||||||
|
Example:
|
||||||
|
return queryInterface.dropTable('users');
|
||||||
|
*/
|
||||||
|
return queryInterface.renameTable('resources', 'comments')
|
||||||
|
}
|
||||||
|
};
|
||||||
Reference in New Issue
Block a user