feat: new follow trusted instance UI, fedi stats, fix #353

This commit is contained in:
lesion 2024-02-28 22:36:33 +01:00
parent 9b1d1023f6
commit 8188d0b4a0
No known key found for this signature in database
GPG key ID: 352918250B012177
4 changed files with 54 additions and 18 deletions

View file

@ -2,7 +2,7 @@
v-container v-container
v-card-title {{$t('common.federation')}} v-card-title {{$t('common.federation')}}
v-card-text v-card-text
v-switch(v-model='enable_federation' v-switch.mt-0(v-model='enable_federation'
:label="$t('admin.enable_federation')" :label="$t('admin.enable_federation')"
persistent-hint persistent-hint
inset inset
@ -65,8 +65,8 @@ v-container
v-btn.mt-4(@click='dialogAddInstance = true' color='primary' text) <v-icon v-text='mdiPlus'></v-icon> {{$t('admin.add_instance')}} v-btn.mt-4(@click='dialogAddInstance = true' color='primary' text) <v-icon v-text='mdiPlus'></v-icon> {{$t('admin.add_instance')}}
v-data-table( v-data-table(
dense
v-if='trusted_instances.length' v-if='trusted_instances.length'
dense
:hide-default-footer='trusted_instances.length<10' :hide-default-footer='trusted_instances.length<10'
:footer-props='{ prevIcon: mdiChevronLeft, nextIcon: mdiChevronRight }' :footer-props='{ prevIcon: mdiChevronLeft, nextIcon: mdiChevronRight }'
:header-props='{ sortIcon: mdiChevronDown }' :header-props='{ sortIcon: mdiChevronDown }'
@ -80,16 +80,19 @@ v-container
span {{ item?.object?.summary ?? item?.instance?.data?.metadata?.nodeDescription}} / {{ item.instance.name }} span {{ item?.object?.summary ?? item?.instance?.data?.metadata?.nodeDescription}} / {{ item.instance.name }}
template(v-slot:item.url="{item}") template(v-slot:item.url="{item}")
a(:href='item.ap_id') {{ item.ap_id }} a(:href='item.ap_id') {{ item.ap_id }}
template(v-slot:item.status="{item}") template(v-slot:item.following="{ item }")
v-switch(:input-value='item.following' :disabled='item.loading' :loading="item.loading === true" @change="() => toggleFollowing(item)" inset hide-details)
template(v-slot:item.follower="{item}")
v-icon(v-if='item.following' v-text='mdiDownload') v-icon(v-if='item.following' v-text='mdiDownload')
v-icon(v-if='item.follower' v-text='mdiUpload') v-icon(v-if='item.follower' v-text='mdiUpload')
template(v-slot:item.actions="{item}") template(v-slot:item.actions="{item}")
//- v-btn(icon @click='deleteInstance(item)' color='error')
//- v-icon(v-text='mdiDeleteForever')
v-btn(icon @click='deleteInstance(item)' color='error') v-btn(icon @click='deleteInstance(item)' color='error')
v-icon(v-text='mdiDeleteForever') v-icon(v-text='mdiDeleteForever')
v-card-title Stats
v-card-text
span {{$t('admin.stats', stats)}}
</template> </template>
<script> <script>
@ -103,25 +106,32 @@ export default {
mdiDeleteForever, mdiPlus, mdiChevronLeft, mdiChevronRight, mdiChevronDown, mdiDownload, mdiUpload, mdiDeleteForever, mdiPlus, mdiChevronLeft, mdiChevronRight, mdiChevronDown, mdiDownload, mdiUpload,
instance_url: '', instance_url: '',
instance_name: $store.state.settings.instance_name, instance_name: $store.state.settings.instance_name,
instance_place: $store.state.settings.instance_place,
trusted_instances_label: $store.state.settings.trusted_instances_label, trusted_instances_label: $store.state.settings.trusted_instances_label,
url2host: $options.filters.url2host, url2host: $options.filters.url2host,
dialogAddInstance: false, dialogAddInstance: false,
stats: {},
loading: false, loading: false,
trusted_instances: [], trusted_instances: [],
loading_instances: {},
valid: false, valid: false,
headers: [ headers: [
{ value: 'logo', text: 'Logo', width: 60, sortable: false }, { value: 'logo', text: 'Logo', width: 60, sortable: false },
{ value: 'name', text: 'Name' }, { value: 'name', text: 'Name' },
{ value: 'info', text: 'Info' }, { value: 'info', text: 'Info' },
{ value: 'url', text: 'URL' }, { value: 'url', text: 'URL' },
{ value: 'status', text: 'Status' }, { value: 'following', text: 'Following' },
{ value: 'follower', text: 'Follower' },
{ value: 'actions', text: 'Actions', align: 'right' } { value: 'actions', text: 'Actions', align: 'right' }
] ]
} }
}, },
async fetch() { async fetch() {
this.trusted_instances = await this.$axios.$get('/instances/trusted') this.stats = await this.$axios.$get('/instances/stats')
const trusted_instances = await this.$axios.$get('/instances/trusted')
this.trusted_instances = trusted_instances.map(t => {
t.loading = false
return t
})
}, },
computed: { computed: {
...mapState(['settings']), ...mapState(['settings']),
@ -152,9 +162,6 @@ export default {
if (!this.$refs.form.validate()) { return } if (!this.$refs.form.validate()) { return }
this.loading = true this.loading = true
try { try {
// if (!this.instance_url.startsWith('http')) {
// this.instance_url = `https://${this.instance_url}`
// }
this.instance_url = this.instance_url.replace(/\/$/, '') this.instance_url = this.instance_url.replace(/\/$/, '')
await this.$axios.$post('/instances/add_trust', { url: this.instance_url }) await this.$axios.$post('/instances/add_trust', { url: this.instance_url })
this.$refs.form.reset() this.$refs.form.reset()
@ -178,6 +185,17 @@ export default {
this.$root.$message(e, { color: 'error' }) this.$root.$message(e, { color: 'error' })
} }
}, },
async toggleFollowing (instance) {
try {
instance.loading = true
await this.$axios.$put('/instances/follow', { ap_id: instance.ap_id })
this.$root.$message('common.ok', { color: 'success' })
} catch (e) {
this.$root.$message(e, { color: 'error' })
}
instance.loading = false
this.$fetch()
},
save (key, value) { save (key, value) {
if (this.settings[key] !== value) { if (this.settings[key] !== value) {
this.setSetting({ key, value }) this.setSetting({ key, value })

View file

@ -320,7 +320,8 @@
"tilelayer_test_error": "The tilelayer service is not reachable at {service_name}", "tilelayer_test_error": "The tilelayer service is not reachable at {service_name}",
"geolocation": "Geolocation", "geolocation": "Geolocation",
"colors": "Colors", "colors": "Colors",
"tag_renamed": "Tag \"{oldTag}\" renamed to \"{newTag}\"" "tag_renamed": "Tag \"{oldTag}\" renamed to \"{newTag}\"",
"stats": "{n_followers} \"actors\" are following this instance, there are {n_events} events from the fediverse and {n_resources} comments"
}, },
"auth": { "auth": {
"not_confirmed": "Not confirmed yet…", "not_confirmed": "Not confirmed yet…",

View file

@ -97,6 +97,24 @@ const instancesController = {
}, },
async toggleFollow (req, res) {
if (!req.body.ap_id) {
return res.status(400).send('ap_id parameter is missing')
}
try {
const ap_actor = await APUser.findByPk(req.body.ap_id, { include: Instance })
if (ap_actor.following) {
await unfollowActor(ap_actor)
} else {
await followActor(ap_actor)
}
return res.sendStatus(200)
} catch (e) {
return res.status(400).send(e)
}
},
async addTrust (req, res) { async addTrust (req, res) {
/** /**
@ -130,7 +148,6 @@ const instancesController = {
const actor = await getActor(actor_url.href, instance) const actor = await getActor(actor_url.href, instance)
log.debug('[FEDI] Actor %s', actor) log.debug('[FEDI] Actor %s', actor)
await actor.update({ trusted: true }) await actor.update({ trusted: true })
await followActor(actor)
return res.json(actor) return res.json(actor)
} }
} catch (e) { } catch (e) {
@ -171,7 +188,6 @@ const instancesController = {
actor = await getActor(instance.applicationActor, instance) actor = await getActor(instance.applicationActor, instance)
log.debug('[FEDI] Actor %s', actor) log.debug('[FEDI] Actor %s', actor)
await actor.update({ trusted: true }) await actor.update({ trusted: true })
await followActor(actor)
return res.json(actor) return res.json(actor)
} }
@ -199,7 +215,6 @@ const instancesController = {
// retrieve the AP actor and flat it as trusted // retrieve the AP actor and flat it as trusted
const actor = await getActor(actorURL, instance) const actor = await getActor(actorURL, instance)
await actor.update({ trusted: true }) await actor.update({ trusted: true })
await followActor(actor)
return res.json(actor) return res.json(actor)
} }
return res.sendStatus(404) return res.sendStatus(404)

View file

@ -203,9 +203,11 @@ module.exports = () => {
// - FEDIVERSE INSTANCES, MODERATION, RESOURCES // - FEDIVERSE INSTANCES, MODERATION, RESOURCES
api.get('/instances', isAdminOrEditor, instanceController.getAll) api.get('/instances', isAdminOrEditor, instanceController.getAll)
api.get('/instances/trusted', instanceController.getTrusted) api.get('/instances/trusted', instanceController.getTrusted)
api.get('/instances/:instance_domain', isAdminOrEditor, instanceController.get) api.get('/instances/stats', isAdminOrEditor, instanceController.stats)
api.put('/instances/follow', isAdminOrEditor, instanceController.toggleFollow)
api.post('/instances/toggle_block', isAdminOrEditor, instanceController.toggleBlock) api.post('/instances/toggle_block', isAdminOrEditor, instanceController.toggleBlock)
api.post('/instances/toggle_user_block', isAdminOrEditor, apUserController.toggleBlock) api.post('/instances/toggle_user_block', isAdminOrEditor, apUserController.toggleBlock)
api.get('/instances/:instance_domain', isAdminOrEditor, instanceController.get)
api.post('/instances/add_trust', isAdmin, instanceController.addTrust) api.post('/instances/add_trust', isAdmin, instanceController.addTrust)
api.delete('/instances/trust', isAdmin, instanceController.removeTrust) api.delete('/instances/trust', isAdmin, instanceController.removeTrust)
api.put('/resources/:resource_id', isAdminOrEditor, resourceController.hide) api.put('/resources/:resource_id', isAdminOrEditor, resourceController.hide)