mirror of
https://framagit.org/les/gancio.git
synced 2025-01-31 16:42:22 +01:00
feat: new follow trusted instance UI, fedi stats, fix #353
This commit is contained in:
parent
9b1d1023f6
commit
8188d0b4a0
4 changed files with 54 additions and 18 deletions
|
@ -2,7 +2,7 @@
|
|||
v-container
|
||||
v-card-title {{$t('common.federation')}}
|
||||
v-card-text
|
||||
v-switch(v-model='enable_federation'
|
||||
v-switch.mt-0(v-model='enable_federation'
|
||||
:label="$t('admin.enable_federation')"
|
||||
persistent-hint
|
||||
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-data-table(
|
||||
dense
|
||||
v-if='trusted_instances.length'
|
||||
dense
|
||||
:hide-default-footer='trusted_instances.length<10'
|
||||
:footer-props='{ prevIcon: mdiChevronLeft, nextIcon: mdiChevronRight }'
|
||||
:header-props='{ sortIcon: mdiChevronDown }'
|
||||
|
@ -80,16 +80,19 @@ v-container
|
|||
span {{ item?.object?.summary ?? item?.instance?.data?.metadata?.nodeDescription}} / {{ item.instance.name }}
|
||||
template(v-slot:item.url="{item}")
|
||||
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.follower' v-text='mdiUpload')
|
||||
|
||||
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-icon(v-text='mdiDeleteForever')
|
||||
|
||||
v-card-title Stats
|
||||
v-card-text
|
||||
span {{$t('admin.stats', stats)}}
|
||||
|
||||
</template>
|
||||
<script>
|
||||
|
@ -103,25 +106,32 @@ export default {
|
|||
mdiDeleteForever, mdiPlus, mdiChevronLeft, mdiChevronRight, mdiChevronDown, mdiDownload, mdiUpload,
|
||||
instance_url: '',
|
||||
instance_name: $store.state.settings.instance_name,
|
||||
instance_place: $store.state.settings.instance_place,
|
||||
trusted_instances_label: $store.state.settings.trusted_instances_label,
|
||||
url2host: $options.filters.url2host,
|
||||
dialogAddInstance: false,
|
||||
stats: {},
|
||||
loading: false,
|
||||
trusted_instances: [],
|
||||
loading_instances: {},
|
||||
valid: false,
|
||||
headers: [
|
||||
{ value: 'logo', text: 'Logo', width: 60, sortable: false },
|
||||
{ value: 'name', text: 'Name' },
|
||||
{ value: 'info', text: 'Info' },
|
||||
{ value: 'url', text: 'URL' },
|
||||
{ value: 'status', text: 'Status' },
|
||||
{ value: 'following', text: 'Following' },
|
||||
{ value: 'follower', text: 'Follower' },
|
||||
{ value: 'actions', text: 'Actions', align: 'right' }
|
||||
]
|
||||
}
|
||||
},
|
||||
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: {
|
||||
...mapState(['settings']),
|
||||
|
@ -152,9 +162,6 @@ export default {
|
|||
if (!this.$refs.form.validate()) { return }
|
||||
this.loading = true
|
||||
try {
|
||||
// if (!this.instance_url.startsWith('http')) {
|
||||
// this.instance_url = `https://${this.instance_url}`
|
||||
// }
|
||||
this.instance_url = this.instance_url.replace(/\/$/, '')
|
||||
await this.$axios.$post('/instances/add_trust', { url: this.instance_url })
|
||||
this.$refs.form.reset()
|
||||
|
@ -178,6 +185,17 @@ export default {
|
|||
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) {
|
||||
if (this.settings[key] !== value) {
|
||||
this.setSetting({ key, value })
|
||||
|
|
|
@ -320,7 +320,8 @@
|
|||
"tilelayer_test_error": "The tilelayer service is not reachable at {service_name}",
|
||||
"geolocation": "Geolocation",
|
||||
"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": {
|
||||
"not_confirmed": "Not confirmed yet…",
|
||||
|
|
|
@ -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) {
|
||||
|
||||
/**
|
||||
|
@ -130,7 +148,6 @@ const instancesController = {
|
|||
const actor = await getActor(actor_url.href, instance)
|
||||
log.debug('[FEDI] Actor %s', actor)
|
||||
await actor.update({ trusted: true })
|
||||
await followActor(actor)
|
||||
return res.json(actor)
|
||||
}
|
||||
} catch (e) {
|
||||
|
@ -171,7 +188,6 @@ const instancesController = {
|
|||
actor = await getActor(instance.applicationActor, instance)
|
||||
log.debug('[FEDI] Actor %s', actor)
|
||||
await actor.update({ trusted: true })
|
||||
await followActor(actor)
|
||||
return res.json(actor)
|
||||
}
|
||||
|
||||
|
@ -199,7 +215,6 @@ const instancesController = {
|
|||
// retrieve the AP actor and flat it as trusted
|
||||
const actor = await getActor(actorURL, instance)
|
||||
await actor.update({ trusted: true })
|
||||
await followActor(actor)
|
||||
return res.json(actor)
|
||||
}
|
||||
return res.sendStatus(404)
|
||||
|
|
|
@ -203,9 +203,11 @@ module.exports = () => {
|
|||
// - FEDIVERSE INSTANCES, MODERATION, RESOURCES
|
||||
api.get('/instances', isAdminOrEditor, instanceController.getAll)
|
||||
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_user_block', isAdminOrEditor, apUserController.toggleBlock)
|
||||
api.get('/instances/:instance_domain', isAdminOrEditor, instanceController.get)
|
||||
api.post('/instances/add_trust', isAdmin, instanceController.addTrust)
|
||||
api.delete('/instances/trust', isAdmin, instanceController.removeTrust)
|
||||
api.put('/resources/:resource_id', isAdminOrEditor, resourceController.hide)
|
||||
|
|
Loading…
Reference in a new issue