Verified Commit 45fa0e19 authored by Eliot Berriot's avatar Eliot Berriot
Browse files

Added input to select max days

parent ce5f21fe
......@@ -11,7 +11,7 @@
<p>{{ account._source.label }}</p>
<div v-if="isLoadingSources && results[account.id] && results[account.id].results.isLoading">
<div class="progress">
<div v-if="results[account.id].results.progress === 'indeterminate'" :class="indeterminate"></div>
<div v-if="results[account.id].results.progress === 'indeterminate'" class="indeterminate"></div>
<div v-else class="determinate" :style="{width: `${results[account.id].results.progress}%`}"></div>
</div>
{{ results[account.id].results.status }}
......@@ -24,9 +24,15 @@
<button
@click="fetch()"
:class="['waves-effect', 'waves-light', {disabled: isLoading}, 'btn-small']" :disabled="isLoading">
<i class="material-icons left">refresh</i>Fetch data
<i class="material-icons left">refresh</i>Fetch {{ maxDays }} days of data
</button>
</h2>
<div class="row">
<div class="input-field col s3">
<input v-model="maxDays" id="maxDays" placeholder="60" type="number" min="1" step="5" max="365" class="validate">
<label class="active" for="maxDays">Period (in days)</label>
</div>
</div>
<div v-if="isLoading" class="progress">
<div class="indeterminate"></div>
</div>
......@@ -69,6 +75,7 @@ import axios from 'axios'
export default {
data () {
return {
maxDays: 60,
isLoadingSources: false,
isLoadingRetribute: false,
results: {},
......@@ -152,7 +159,7 @@ export default {
this.isLoadingSources = true
accounts.forEach((a) => {
let r = {isLoading: true, progress: 'indeterminate', status: ''}
let promise = a._source.fetch({account: a, store: this.$store, results: r, vue: this})
let promise = a._source.fetch({account: a, store: this.$store, results: r, vue: this, maxDays: this.maxDays})
this.$set(this.results, a.id, {account: a, promise, results: r})
})
const keys = Object.keys(this.results)
......
import axios from 'axios'
import moment from 'moment'
import Form from '../components/MastodonForm.vue'
import parseLink from 'parse-link-header'
......@@ -82,29 +83,37 @@ export default {
store.commit('addAccount', {source: 'mastodon', raw: accountResponse.data, username: accountResponse.data.acct, domain})
router.push({path: '/'})
},
async fetch ({account, cache, store, results, vue}) {
async fetch ({account, store, results, maxDays}) {
results.status = `Fetching favorites...`
const token = store.state.sources.mastodon.appTokens[`${account.username}@${account.domain}`].access_token
const client = axios.create({
baseURL: `https://${account.domain}`,
headers: {'Authorization': `Bearer ${token}`},
})
const maxFavorites = 400
const dateLimit = moment().subtract(maxDays, 'days')
let url = '/api/v1/favourites'
let handledFavorites = 0
results.progress = 0
// results.progress = 0
// results.progressCount
results.accounts = {}
while (handledFavorites < maxFavorites) {
let cont = true
while (cont) {
let response = await client.get(url, {params: {limit: 40}})
response.data.forEach((f) => {
let date = moment(f.created_at)
if (date.isBefore(dateLimit)) {
cont = false
return
}
handledFavorites += 1
results.progressCount += 1
let account = `webfinger:${f.account.acct}`
if (results.accounts[account]) {
results.accounts[account].weight += 1
} else {
results.accounts[account] = {weight: 1, source: 'webfinger', id: f.account.acct, avatar: f.account.avatar, name: f.account.display_name, url: f.account.url}
}
results.progress = Math.min(100, handledFavorites / maxFavorites * 100)
// results.progress = Math.min(100, handledFavorites / maxFavorites * 100)
})
let link = response.headers.link || ''
let parsed = parseLink(link)
......@@ -113,7 +122,7 @@ export default {
} else {
break
}
results.status = `Fetched favorites ${handledFavorites}/${maxFavorites}`
results.status = `Fetched ${handledFavorites} favorites`
}
results.isLoading = false
return results
......
......@@ -17,12 +17,12 @@ export const storeConfig = {
cache: {}
},
mutations: {
addAccount (state, payload) {
addAccount ({state}, payload) {
const id = sources.sources[payload.source].authDataToKey(payload)
payload.id = id
state.accounts[id] = payload
},
setRecursiveState (state, {key, suffix, value}) {
setRecursiveState ({state}, {key, suffix, value}) {
if (suffix) {
let existing = get(state, key, {})
existing[suffix] = value
......
......@@ -5438,6 +5438,11 @@ mocha@^5.2.0:
mkdirp "0.5.1"
supports-color "5.4.0"
moment@^2.24.0:
version "2.24.0"
resolved "https://registry.yarnpkg.com/moment/-/moment-2.24.0.tgz#0d055d53f5052aa653c9f6eb68bb5d12bf5c2b5b"
integrity sha512-bV7f+6l2QigeBBZSM/6yTNq4P2fNpSWj/0e7jQcy87A8e7o2nAfP/34/2ky5Vw4B9S446EtIhodAzkFCcR4dQg==
move-concurrently@^1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/move-concurrently/-/move-concurrently-1.0.1.tgz#be2c005fda32e0b29af1f05d7c4b33214c701f92"
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment