we can fetch timelines!
This commit is contained in:
parent
9753b3d1c6
commit
e7d8632154
|
@ -48,4 +48,15 @@ export function getAccessTokenFromAuthCode(instanceName, clientId, clientSecret,
|
||||||
code: code
|
code: code
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getHomeTimeline(instanceName, accessToken) {
|
||||||
|
let url = `https://${instanceName}/api/v1/timelines/home`
|
||||||
|
return fetch(url, {
|
||||||
|
method: 'GET',
|
||||||
|
headers: {
|
||||||
|
'Accept': 'application/json',
|
||||||
|
'Authorization': `Bearer ${accessToken}`
|
||||||
|
}
|
||||||
|
})
|
||||||
}
|
}
|
|
@ -15,13 +15,29 @@
|
||||||
</Layout>
|
</Layout>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import Layout from './_components/Layout.html';
|
import Layout from './_components/Layout.html'
|
||||||
|
import { databasePromise } from './_utils/database'
|
||||||
|
import { getHomeTimeline } from './_utils/mastodon'
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
|
oncreate: function () {
|
||||||
|
if (process.browser) {
|
||||||
|
(async () => {
|
||||||
|
let db = await databasePromise
|
||||||
|
let instanceData = await db.get('instance')
|
||||||
|
if (!instanceData) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
let response = await (await getHomeTimeline(instanceData.instanceName, instanceData.access_token)).json()
|
||||||
|
console.log(response)
|
||||||
|
|
||||||
|
})()
|
||||||
|
}
|
||||||
|
},
|
||||||
components: {
|
components: {
|
||||||
Layout
|
Layout
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
</script>
|
</script>
|
||||||
<style>
|
<style>
|
||||||
.banner {
|
.banner {
|
||||||
|
|
|
@ -45,6 +45,7 @@
|
||||||
import Layout from '../_components/Layout.html';
|
import Layout from '../_components/Layout.html';
|
||||||
import { registerApplication, generateAuthLink, getAccessTokenFromAuthCode } from '../_utils/mastodon'
|
import { registerApplication, generateAuthLink, getAccessTokenFromAuthCode } from '../_utils/mastodon'
|
||||||
import { databasePromise } from '../_utils/database'
|
import { databasePromise } from '../_utils/database'
|
||||||
|
import { goto } from 'sapper/runtime.js'
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
oncreate: function () {
|
oncreate: function () {
|
||||||
|
@ -65,7 +66,7 @@
|
||||||
)).json()
|
)).json()
|
||||||
instanceData = Object.assign(instanceData, response)
|
instanceData = Object.assign(instanceData, response)
|
||||||
await db.set(`instance`, instanceData)
|
await db.set(`instance`, instanceData)
|
||||||
console.log('response', response)
|
goto('/')
|
||||||
}
|
}
|
||||||
})()
|
})()
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue