mirror of
https://framagit.org/les/gancio.git
synced 2025-01-31 16:42:22 +01:00
adds and removes friendly instances
This commit is contained in:
parent
d4db4e3d67
commit
f820baa410
8 changed files with 67 additions and 32 deletions
|
@ -8,21 +8,21 @@ v-footer(aria-label='Footer')
|
|||
:key='link.label' color='primary' text
|
||||
:href='link.href' :to='link.to' :target="link.href && '_blank'") {{link.label}}
|
||||
|
||||
v-menu(v-if='settings.enable_trusted_instances && settings.trusted_instances && settings.trusted_instances.length'
|
||||
v-menu(v-if='settings.enable_trusted_instances && trusted_instances?.length'
|
||||
offset-y bottom open-on-hover transition="slide-y-transition")
|
||||
template(v-slot:activator="{ on, attrs }")
|
||||
v-btn.ml-1(v-bind='attrs' v-on='on' color='primary' text) {{ settings.trusted_instances_label || $t('admin.trusted_instances_label_default')}}
|
||||
v-list(subheaders two-lines)
|
||||
v-list-item(v-for='instance in settings.trusted_instances'
|
||||
v-list-item(v-for='instance in trusted_instances'
|
||||
:key='instance.name'
|
||||
target='_blank'
|
||||
:href='instance.url'
|
||||
:href='instance.ap_id'
|
||||
two-line)
|
||||
//- p {{ instance.object }}
|
||||
v-list-item-avatar
|
||||
v-img(:src='`${instance.url}/logo.png`')
|
||||
v-img(:src='instance.object.icon.url')
|
||||
v-list-item-content
|
||||
v-list-item-title {{instance.name}}
|
||||
v-list-item-subtitle {{instance.label}}
|
||||
v-list-item-title {{instance.object.preferredUsername}}
|
||||
|
||||
v-btn.ml-1(v-if='settings.enable_federation' color='primary' text rel='me' @click.prevent='showFollowMe=true') {{$t('event.interact_with_me')}}
|
||||
v-spacer
|
||||
|
@ -37,9 +37,16 @@ export default {
|
|||
components: { FollowMe },
|
||||
data () {
|
||||
return {
|
||||
showFollowMe: false
|
||||
showFollowMe: false,
|
||||
trusted_instances: []
|
||||
}
|
||||
},
|
||||
created () {
|
||||
this.$root.$on('update_friendly_instances', this.$fetch)
|
||||
},
|
||||
async fetch () {
|
||||
this.trusted_instances = await this.$axios.$get('/instances/friendly')
|
||||
},
|
||||
computed: {
|
||||
...mapState(['settings']),
|
||||
footerLinks () {
|
||||
|
|
|
@ -78,7 +78,6 @@ v-container
|
|||
</template>
|
||||
<script>
|
||||
import { mapActions, mapState } from 'vuex'
|
||||
import get from 'lodash/get'
|
||||
import { mdiDeleteForever, mdiPlus, mdiChevronLeft, mdiChevronRight, mdiChevronDown } from '@mdi/js'
|
||||
|
||||
export default {
|
||||
|
@ -96,9 +95,8 @@ export default {
|
|||
friendly_instances: [],
|
||||
valid: false,
|
||||
headers: [
|
||||
{ value: 'object.id', text: 'Name' },
|
||||
{ value: 'object.preferredUsername', text: 'Name' },
|
||||
{ value: 'ap_id', text: 'URL' },
|
||||
{ value: 'instance.domain', text: 'Instance' },
|
||||
{ value: 'actions', text: 'Actions', align: 'right' }
|
||||
]
|
||||
}
|
||||
|
@ -139,18 +137,11 @@ export default {
|
|||
this.instance_url = `https://${this.instance_url}`
|
||||
}
|
||||
this.instance_url = this.instance_url.replace(/\/$/, '')
|
||||
// const instance = await this.$axios.$get(`${this.instance_url}/.well-known/nodeinfo/2.1`)
|
||||
const ret = await this.$axios.$post('/instances/add_friendly', { instance_url: this.instance_url })
|
||||
// this.setSetting({
|
||||
// key: 'trusted_instances',
|
||||
// value: this.settings.trusted_instances.concat({
|
||||
// url: this.instance_url,
|
||||
// name: get(instance, 'metadata.nodeName', ''),
|
||||
// label: get(instance, 'metadata.nodeLabel', '')
|
||||
// })
|
||||
// })
|
||||
await this.$axios.$post('/instances/add_friendly', { instance_url: this.instance_url })
|
||||
this.$refs.form.reset()
|
||||
this.$fetch()
|
||||
this.dialogAddInstance = false
|
||||
this.$root.$emit('update_friendly_instances')
|
||||
} catch (e) {
|
||||
this.$root.$message(e, { color: 'error' })
|
||||
}
|
||||
|
@ -159,10 +150,14 @@ export default {
|
|||
async deleteInstance (instance) {
|
||||
const ret = await this.$root.$confirm('admin.delete_trusted_instance_confirm')
|
||||
if (!ret) { return }
|
||||
this.setSetting({
|
||||
key: 'trusted_instances',
|
||||
value: this.settings.trusted_instances.filter(i => i.url !== instance.url)
|
||||
})
|
||||
try {
|
||||
await this.$axios.$delete('/instances/friendly', { params: { ap_id: instance.ap_id }})
|
||||
this.$fetch()
|
||||
this.$root.$emit('update_friendly_instances')
|
||||
this.$root.$message('admin.instance_removed', { color: 'success' })
|
||||
} catch (e) {
|
||||
this.$root.$message(e, { color: 'error' })
|
||||
}
|
||||
},
|
||||
save (key, value) {
|
||||
if (this.settings[key] !== value) {
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
const { APUser, Instance, Resource } = require('../models/models')
|
||||
const { getActor, followActor } = require('../../federation/helpers')
|
||||
const { getActor, unfollowActor } = require('../../federation/helpers')
|
||||
const axios = require('axios')
|
||||
const get = require('lodash/get')
|
||||
|
||||
|
@ -50,7 +50,7 @@ const instancesController = {
|
|||
},
|
||||
|
||||
async getFriendly (req, res) {
|
||||
const friendly_instances = await APUser.findAll({ where: { following: true }, include: [Instance]})
|
||||
const friendly_instances = await APUser.findAll({ where: { friendly: true }, include: [Instance]})
|
||||
return res.json(friendly_instances)
|
||||
},
|
||||
|
||||
|
@ -61,9 +61,37 @@ const instancesController = {
|
|||
return res.json(instance)
|
||||
},
|
||||
|
||||
|
||||
async removeFriendly (req, res) {
|
||||
let ap_id = req.query.ap_id
|
||||
log.info(`Remove friendly instance ${ap_id} ...`)
|
||||
|
||||
try {
|
||||
const actor = await getActor(ap_id)
|
||||
if (!actor || !actor.friendly) {
|
||||
return res.sendStatus(404)
|
||||
}
|
||||
|
||||
if (actor.following) {
|
||||
// unfollow
|
||||
await unfollowActor(actor)
|
||||
}
|
||||
|
||||
// remove friendlyness
|
||||
await actor.update({ friendly: false })
|
||||
|
||||
} catch (e) {
|
||||
log.warn(e)
|
||||
return res.status(400).send(e)
|
||||
}
|
||||
|
||||
return res.sendStatus(200)
|
||||
|
||||
},
|
||||
|
||||
async addFriendly (req, res) {
|
||||
|
||||
let instance_url= req.body.instance_url
|
||||
let instance_url = req.body.instance_url
|
||||
try {
|
||||
if (!instance_url.startsWith('http')) {
|
||||
instance_url = `https://${instance_url}`
|
||||
|
@ -84,7 +112,7 @@ const instancesController = {
|
|||
|
||||
log.debug(`instance .well-known: ${instance.name} / ${instance.actor}`)
|
||||
|
||||
// if we have an actor, let's follow him
|
||||
// if we have an actor, let's make friend
|
||||
if (instance.actor) {
|
||||
|
||||
// send a well-known request
|
||||
|
@ -94,10 +122,10 @@ const instancesController = {
|
|||
// search for actor url
|
||||
const actorURL = wellknown?.links.find(l => l.rel === 'self').href
|
||||
|
||||
// retrieve the AP actor
|
||||
// retrieve the AP actor and flat it as friendly
|
||||
const actor = await getActor(actorURL)
|
||||
await actor.update({ friendly: true })
|
||||
|
||||
await followActor(actor)
|
||||
return res.json(actor)
|
||||
}
|
||||
} catch (e) {
|
||||
|
|
|
@ -21,7 +21,7 @@ const defaultSettings = {
|
|||
hostname: defaultHostname,
|
||||
instance_timezone: 'Europe/Rome',
|
||||
instance_locale: 'en',
|
||||
instance_name: 'gancio',
|
||||
instance_name: 'relay',
|
||||
instance_place: '',
|
||||
allow_registration: true,
|
||||
allow_anon_event: true,
|
||||
|
|
|
@ -200,6 +200,7 @@ module.exports = () => {
|
|||
api.post('/instances/toggle_block', isAdmin, instanceController.toggleBlock)
|
||||
api.post('/instances/toggle_user_block', isAdmin, apUserController.toggleBlock)
|
||||
api.post('/instances/add_friendly', isAdmin, instanceController.addFriendly)
|
||||
api.delete('/instances/friendly', isAdmin, instanceController.removeFriendly)
|
||||
api.put('/resources/:resource_id', isAdmin, resourceController.hide)
|
||||
api.delete('/resources/:resource_id', isAdmin, resourceController.remove)
|
||||
api.get('/resources', isAdmin, resourceController.getAll)
|
||||
|
|
|
@ -7,6 +7,7 @@ module.exports = (sequelize, DataTypes) =>
|
|||
},
|
||||
follower: DataTypes.BOOLEAN,
|
||||
following: DataTypes.BOOLEAN,
|
||||
friendly: DataTypes.BOOLEAN,
|
||||
blocked: DataTypes.BOOLEAN,
|
||||
object: DataTypes.JSON
|
||||
})
|
||||
|
|
|
@ -30,7 +30,7 @@ module.exports = {
|
|||
type: 'Application',
|
||||
summary: config.description,
|
||||
name,
|
||||
preferredUsername: name,
|
||||
preferredUsername: settings.instance_place,
|
||||
inbox: `${config.baseurl}/federation/u/${name}/inbox`,
|
||||
outbox: `${config.baseurl}/federation/u/${name}/outbox`,
|
||||
endpoints: { sharedInbox: `${config.baseurl}/federation/u/${name}/inbox` },
|
||||
|
|
|
@ -12,6 +12,7 @@ module.exports = {
|
|||
return Promise.all(
|
||||
[
|
||||
await queryInterface.addColumn('ap_users', 'following', { type: Sequelize.BOOLEAN }),
|
||||
await queryInterface.addColumn('ap_users', 'friendly', { type: Sequelize.BOOLEAN }),
|
||||
await queryInterface.addColumn('events', 'apUserApId', {
|
||||
type: Sequelize.STRING,
|
||||
references: {
|
||||
|
@ -34,7 +35,9 @@ module.exports = {
|
|||
*/
|
||||
return Promise.all(
|
||||
[
|
||||
await queryInterface.removeColumn('events', 'apUserApId'),
|
||||
await queryInterface.removeColumn('ap_users', 'following'),
|
||||
await queryInterface.removeColumn('ap_users', 'friendly'),
|
||||
])
|
||||
}
|
||||
};
|
Loading…
Reference in a new issue