π A self-hostable personal dashboard built for you. Includes status-checking, widgets, themes, icon packs, a UI editor and tons more!
Vue awesomedashboarddockerhomelabhomepagemitnodejsorganizationproductivitypwaself-hostedstartpagevue
π Fixes APOD widget for video days, missing fields and proxy (#2364)
Alicia Sykes8cdbc2d46583
diff --git a/docs/widgets.md b/docs/widgets.mdindex 3400f738..888a092b 100644--- a/docs/widgets.md+++ b/docs/widgets.md@@ -1258,13 +1258,15 @@ Displays airport departure and arrival flights, using data from [AeroDataBox](ht### Astronomy Picture of the Day-Show the NASA Astronomy Picture of the Day. Data is fetched from [APOD](https://apod.nasa.gov/apod/) using [@Lissy93/go-apod](https://github.com/lissy93/go-apod) / hosted at [apod.as93.net](https://apod.as93.net/).+Show the NASA Astronomy Picture of the Day. Data is fetched from [APOD](https://science.nasa.gov/apod/) using [@Lissy93/go-apod](https://github.com/lissy93/go-apod) / hosted at [apod.as93.net](https://apod.as93.net/).<p align="center"><img width="400" src="https://storage.googleapis.com/as93-screenshots/dashy/apod.png" /></p>#### Options-_No config options._+**Field** | **Type** | **Required** | **Description**+--- | --- | --- | ---+**`hostname`** | `string` | _Optional_ | The URL of your own [go-apod](https://github.com/lissy93/go-apod) instance. Defaults to `https://apod.as93.net`#### Example@@ -1272,6 +1274,14 @@ _No config options._- type: apod```+Or, using a self-hosted instance:++```yaml+- type: apod+ options:+ hostname: https://apod.example.com+```+#### Info- **CORS**: π’ Enableddiff --git a/src/assets/locales/en.json b/src/assets/locales/en.jsonindex 73e72ab5..4c688e54 100644--- a/src/assets/locales/en.json+++ b/src/assets/locales/en.json@@ -448,6 +448,9 @@"show-less": "Show Less","open-link": "Continue Reading"},+ "apod": {+ "watch-video": "Watch Video"+ },"calendar": {"all-day": "All day","no-events": "Nothing coming up",diff --git a/src/components/Widgets/Apod.vue b/src/components/Widgets/Apod.vueindex ddacc443..40aef99d 100644--- a/src/components/Widgets/Apod.vue+++ b/src/components/Widgets/Apod.vue@@ -1,21 +1,30 @@<template>-<div class="apod-wrapper" v-if="url">- <a :href="link" class="title" target="__blank" title="View Article">+<div class="apod-wrapper" v-if="title">+ <a :href="articleUrl" class="title" target="_blank" rel="noopener noreferrer" title="View Article">{{ title }}</a>- <a :href="hdurl" title="View HD Image" class="picture" target="__blank">- <img :src="url" :alt="title" />+ <a+ v-if="image"+ :href="mediaLink"+ :title="isVideo ? null : 'View HD Image'"+ class="picture"+ target="_blank"+ rel="noopener noreferrer"+ >+ <img :src="image" :alt="title" /></a>- <p class="copyright">{{ copyright }}</p>+ <a v-if="isVideo" :href="mediaLink" class="watch-video" target="_blank" rel="noopener noreferrer">+ {{ $t('widgets.apod.watch-video') }}+ </a>+ <p class="copyright" v-if="copyright">{{ copyright }}</p><p class="explanation">{{ truncatedExplanation }}</p>- <p @click="toggleShowFull" class="expend-details-btn">+ <p @click="toggleShowFull" class="expend-details-btn" v-if="isTruncated">{{ showFullExp ? $t('widgets.general.show-less') : $t('widgets.general.show-more') }}</p></div></template><script>-import request from '@/utils/request';import WidgetMixin from '@/mixins/WidgetMixin';import { widgetApiEndpoints } from '@/utils/config/defaults';@@ -24,38 +33,58 @@ export default {data() {return {title: null,+ date: null,+ mediaType: null,url: null,hdurl: null,- link: 'https://apod.nasa.gov/apod/astropix.html',- explanation: null,+ thumbnail: null,+ explanation: '',copyright: null,showFullExp: false,};},computed: {+ endpoint() {+ const host = this.parseAsEnvVar(this.options.hostname);+ return host ? `${host.replace(/\/+$/, '')}/apod` : widgetApiEndpoints.astronomyPictureOfTheDay;+ },+ articleUrl() {+ const base = 'https://science.nasa.gov/apod/';+ return this.date ? `${base}?date=${this.date}` : base;+ },+ isVideo() {+ return this.mediaType === 'video';+ },+ image() {+ return this.isVideo ? this.thumbnail : this.url || this.hdurl;+ },+ mediaLink() {+ return (this.isVideo ? this.url : this.hdurl || this.url) || this.articleUrl;+ },+ isTruncated() {+ return this.explanation.length > 100;+ },truncatedExplanation() {- return this.showFullExp ? this.explanation : `${this.explanation.substring(0, 100)}...`;+ if (this.showFullExp || !this.isTruncated) return this.explanation;+ return `${this.explanation.slice(0, 100).replace(/\s+\S*$/, '')}...`;},},methods: {fetchData() {- request.get(widgetApiEndpoints.astronomyPictureOfTheDay)- .then((response) => {- this.processData(response.data);- })- .catch((dataFetchError) => {- this.error('Unable to fetch data', dataFetchError);- })- .finally(() => {- this.finishLoading();- });+ this.makeRequest(this.endpoint).then(this.processData);},processData(data) {+ if (!data?.title) {+ this.error('Unexpected response from APOD API', data);+ return;+ }this.title = data.title;+ this.date = data.date;+ this.mediaType = data.media_type;this.url = data.url;this.hdurl = data.hdurl;- this.link = data.link;- this.explanation = data.explanation;+ this.thumbnail = data.thumbnail_url;+ this.explanation = data.explanation || '';this.copyright = data.copyright;},toggleShowFull() {@@ -67,6 +96,7 @@ export default {<style scoped lang="scss">.apod-wrapper {+ display: flow-root;a.title {font-size: 1.5rem;margin: 0.5rem 0;@@ -79,6 +109,11 @@ export default {margin: 0.5rem auto;border-radius: var(--curve-factor);}+ a.watch-video {+ display: block;+ margin: 0.2rem 0;+ color: var(--widget-text-color);+ }p.copyright {font-size: 0.8rem;margin: 0.2rem 0;