Begin to work on no gpodder enabled
This commit is contained in:
parent
6047d913aa
commit
48fef0d993
@ -4,12 +4,14 @@ declare(strict_types=1);
|
||||
|
||||
namespace OCA\RePod\AppInfo;
|
||||
|
||||
use OCP\App\AppPathNotFoundException;
|
||||
use OCP\App\IAppManager;
|
||||
use OCP\AppFramework\App;
|
||||
use OCP\AppFramework\Bootstrap\IBootContext;
|
||||
use OCP\AppFramework\Bootstrap\IBootstrap;
|
||||
use OCP\AppFramework\Bootstrap\IRegistrationContext;
|
||||
use OCP\IUserSession;
|
||||
use OCP\Server;
|
||||
use OCP\Util;
|
||||
|
||||
class Application extends App implements IBootstrap
|
||||
{
|
||||
@ -25,15 +27,33 @@ class Application extends App implements IBootstrap
|
||||
$appContainer = $context->getAppContainer();
|
||||
/** @var IAppManager $appManager */
|
||||
$appManager = $appContainer->get(IAppManager::class);
|
||||
/** @var IUserSession $userSession */
|
||||
$userSession = $appContainer->get(IUserSession::class);
|
||||
|
||||
$gpoddersync = $appManager->isEnabledForUser(self::GPODDERSYNC_ID, $userSession->getUser());
|
||||
$gpoddersync = $appManager->isEnabledForUser(self::GPODDERSYNC_ID);
|
||||
if (!$gpoddersync) {
|
||||
$appManager->enableApp(self::GPODDERSYNC_ID);
|
||||
try {
|
||||
$appManager->enableApp(self::GPODDERSYNC_ID);
|
||||
} catch (AppPathNotFoundException $e) {
|
||||
}
|
||||
}
|
||||
|
||||
/** @psalm-suppress DeprecatedMethod */
|
||||
Util::connectHook('\OCP\Config', 'js', $this, 'extendJsConfig');
|
||||
}
|
||||
|
||||
public function register(IRegistrationContext $context): void {
|
||||
}
|
||||
|
||||
public static function extendJsConfig(array $settings): void {
|
||||
/** @var IAppManager $appManager */
|
||||
$appManager = Server::get(IAppManager::class);
|
||||
|
||||
if (is_array($settings['array']) && array_key_exists('oc_appconfig', $settings['array'])) {
|
||||
/** @var array $appConfig */
|
||||
$appConfig = json_decode((string) $settings['array']['oc_appconfig'], true);
|
||||
$appConfig['repod'] = [
|
||||
'gpodder' => $appManager->isEnabledForUser(self::GPODDERSYNC_ID)
|
||||
];
|
||||
$settings['array']['oc_appconfig'] = json_encode($appConfig);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -19,7 +19,7 @@ class TopController extends Controller
|
||||
public function __construct(
|
||||
IRequest $request,
|
||||
private IClientService $clientService,
|
||||
private IFactory $l10nFactory,
|
||||
private IFactory $l10n,
|
||||
private IUserSession $userSession
|
||||
) {
|
||||
parent::__construct(Application::APP_ID, $request);
|
||||
@ -35,7 +35,7 @@ class TopController extends Controller
|
||||
}
|
||||
|
||||
try {
|
||||
$lang = $this->l10nFactory->getUserLanguage($this->userSession->getUser());
|
||||
$lang = $this->l10n->getUserLanguage($this->userSession->getUser());
|
||||
$lang = explode('_', $lang);
|
||||
$lang = count($lang) > 1 ? $lang[1] : $lang[0];
|
||||
$lang = $lang === 'en' ? 'us' : $lang;
|
||||
@ -43,7 +43,7 @@ class TopController extends Controller
|
||||
$client = $this->clientService->newClient();
|
||||
$response = $client->get("https://rss.applemarketingtools.com/api/v2/{$lang}/podcasts/top/{$limit}/podcasts.json");
|
||||
/** @var array $json */
|
||||
$json = json_decode((string) $response->getBody(), flags: JSON_THROW_ON_ERROR);
|
||||
$json = json_decode((string) $response->getBody(), true, flags: JSON_THROW_ON_ERROR);
|
||||
return new JSONResponse($json, $response->getStatusCode());
|
||||
} catch (Exception $e) {
|
||||
return new JSONResponse([$e->getMessage()], Http::STATUS_INTERNAL_SERVER_ERROR);
|
||||
|
103
src/App.vue
103
src/App.vue
@ -1,111 +1,22 @@
|
||||
<template>
|
||||
<NcContent app-name="repod">
|
||||
<NcAppNavigation>
|
||||
<NcAppContentList>
|
||||
<router-link to="/discover">
|
||||
<NcAppNavigationNew :text="t('Add a podcast')">
|
||||
<template #icon>
|
||||
<Plus size="20" />
|
||||
</template>
|
||||
</NcAppNavigationNew>
|
||||
</router-link>
|
||||
<NcLoadingIcon v-if="loading" />
|
||||
<ul v-if="!loading">
|
||||
<NcAppNavigationItem v-for="subscription in subscriptions"
|
||||
:key="subscription.id"
|
||||
:loading="subscription.loading"
|
||||
:title="subscription.title ?? subscription.url">
|
||||
<template #icon>
|
||||
<img :src="subscription.imageUrl" alt="">
|
||||
</template>
|
||||
</NcAppNavigationItem>
|
||||
</ul>
|
||||
</NcAppContentList>
|
||||
</NcAppNavigation>
|
||||
<NcAppContent>
|
||||
<router-view />
|
||||
</NcAppContent>
|
||||
<GPodder v-if="!AppConfig.repod.gpodder" />
|
||||
<Index v-if="AppConfig.repod.gpodder" />
|
||||
</NcContent>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import '@nextcloud/dialogs/dist/index.css'
|
||||
import {
|
||||
NcAppContent,
|
||||
NcAppContentList,
|
||||
NcAppNavigation,
|
||||
NcAppNavigationItem,
|
||||
NcAppNavigationNew,
|
||||
NcContent,
|
||||
NcLoadingIcon,
|
||||
} from '@nextcloud/vue'
|
||||
import Plus from 'vue-material-design-icons/Plus.vue'
|
||||
import axios from '@nextcloud/axios'
|
||||
import { generateUrl } from '@nextcloud/router'
|
||||
import { showError } from '@nextcloud/dialogs'
|
||||
import GPodder from './views/GPodder.vue'
|
||||
import Index from './views/Index.vue'
|
||||
import { NcContent } from '@nextcloud/vue'
|
||||
|
||||
export default {
|
||||
name: 'App',
|
||||
components: {
|
||||
NcAppContent,
|
||||
NcAppContentList,
|
||||
NcAppNavigation,
|
||||
NcAppNavigationItem,
|
||||
NcAppNavigationNew,
|
||||
GPodder,
|
||||
Index,
|
||||
NcContent,
|
||||
NcLoadingIcon,
|
||||
Plus,
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
subscriptions: [],
|
||||
loading: true,
|
||||
}
|
||||
},
|
||||
computed: {
|
||||
},
|
||||
async mounted() {
|
||||
try {
|
||||
const metrics = await axios.get(generateUrl('/apps/gpoddersync/personal_settings/metrics'))
|
||||
for (const subscriptionId in metrics.data.subscriptions) {
|
||||
this.addSubscription({
|
||||
id: subscriptionId,
|
||||
url: metrics.data.subscriptions[subscriptionId].url,
|
||||
loading: true,
|
||||
})
|
||||
}
|
||||
for (const subscription of this.subscriptions) {
|
||||
this.updateSubscriptionMeta(subscription)
|
||||
}
|
||||
} catch (e) {
|
||||
console.error(e)
|
||||
showError(t('Could not fetch subscriptions'))
|
||||
}
|
||||
this.loading = false
|
||||
},
|
||||
methods: {
|
||||
addSubscription(subscription) {
|
||||
const subscriptionId = this.subscriptions.findIndex(sub => sub.url === subscription.url)
|
||||
|
||||
if (subscriptionId === -1) {
|
||||
this.subscriptions.push(subscription)
|
||||
} else {
|
||||
this.subscriptions[subscriptionId] = subscription
|
||||
}
|
||||
|
||||
this.subscriptions.sort((a, b) => {
|
||||
if (a.title && b.title) return a.title.localeCompare(b.title)
|
||||
return a.id - b.id
|
||||
})
|
||||
},
|
||||
async updateSubscriptionMeta(subscription) {
|
||||
try {
|
||||
const podcasts = await axios.get(generateUrl('/apps/gpoddersync/personal_settings/podcast_data?url={url}', { url: subscription.url }))
|
||||
this.addSubscription({ ...podcasts.data.data, ...subscription, ...{ loading: false } })
|
||||
} catch (e) {
|
||||
console.error(e)
|
||||
}
|
||||
},
|
||||
},
|
||||
}
|
||||
</script>
|
||||
|
@ -15,6 +15,8 @@ Vue.mixin({ methods: { t, n } })
|
||||
Vue.use(Plugin)
|
||||
Vue.prototype.OC = window.OC
|
||||
Vue.prototype.OCA = window.OCA
|
||||
Vue.prototype.OCP = window.OCP
|
||||
Vue.prototype.AppConfig = window.oc_appconfig
|
||||
|
||||
export default new Vue({
|
||||
el: '#content',
|
||||
|
9
src/views/GPodder.vue
Normal file
9
src/views/GPodder.vue
Normal file
@ -0,0 +1,9 @@
|
||||
<template>
|
||||
<div>Oui</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
export default {
|
||||
name: 'GPodder',
|
||||
}
|
||||
</script>
|
108
src/views/Index.vue
Normal file
108
src/views/Index.vue
Normal file
@ -0,0 +1,108 @@
|
||||
<template>
|
||||
<fragment>
|
||||
<NcAppNavigation>
|
||||
<NcAppContentList>
|
||||
<router-link to="/discover">
|
||||
<NcAppNavigationNew :text="t('Add a podcast')">
|
||||
<template #icon>
|
||||
<Plus size="20" />
|
||||
</template>
|
||||
</NcAppNavigationNew>
|
||||
</router-link>
|
||||
<NcLoadingIcon v-if="loading" />
|
||||
<ul v-if="!loading">
|
||||
<NcAppNavigationItem v-for="subscription in subscriptions"
|
||||
:key="subscription.id"
|
||||
:loading="subscription.loading"
|
||||
:title="subscription.title ?? subscription.url">
|
||||
<template #icon>
|
||||
<img :src="subscription.imageUrl" alt="">
|
||||
</template>
|
||||
</NcAppNavigationItem>
|
||||
</ul>
|
||||
</NcAppContentList>
|
||||
</NcAppNavigation>
|
||||
<NcAppContent>
|
||||
<router-view />
|
||||
</NcAppContent>
|
||||
</fragment>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import {
|
||||
NcAppContent,
|
||||
NcAppContentList,
|
||||
NcAppNavigation,
|
||||
NcAppNavigationItem,
|
||||
NcAppNavigationNew,
|
||||
NcLoadingIcon,
|
||||
} from '@nextcloud/vue'
|
||||
import Plus from 'vue-material-design-icons/Plus.vue'
|
||||
import axios from '@nextcloud/axios'
|
||||
import { generateUrl } from '@nextcloud/router'
|
||||
import { showError } from '@nextcloud/dialogs'
|
||||
|
||||
export default {
|
||||
name: 'Index',
|
||||
components: {
|
||||
NcAppContent,
|
||||
NcAppContentList,
|
||||
NcAppNavigation,
|
||||
NcAppNavigationItem,
|
||||
NcAppNavigationNew,
|
||||
NcLoadingIcon,
|
||||
Plus,
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
subscriptions: [],
|
||||
loading: true,
|
||||
}
|
||||
},
|
||||
computed: {
|
||||
},
|
||||
async mounted() {
|
||||
try {
|
||||
const metrics = await axios.get(generateUrl('/apps/gpoddersync/personal_settings/metrics'))
|
||||
for (const subscriptionId in metrics.data.subscriptions) {
|
||||
this.addSubscription({
|
||||
id: subscriptionId,
|
||||
url: metrics.data.subscriptions[subscriptionId].url,
|
||||
loading: true,
|
||||
})
|
||||
}
|
||||
for (const subscription of this.subscriptions) {
|
||||
this.updateSubscriptionMeta(subscription)
|
||||
}
|
||||
} catch (e) {
|
||||
console.error(e)
|
||||
showError(t('Could not fetch subscriptions'))
|
||||
}
|
||||
this.loading = false
|
||||
},
|
||||
methods: {
|
||||
addSubscription(subscription) {
|
||||
const subscriptionId = this.subscriptions.findIndex(sub => sub.url === subscription.url)
|
||||
|
||||
if (subscriptionId === -1) {
|
||||
this.subscriptions.push(subscription)
|
||||
} else {
|
||||
this.subscriptions[subscriptionId] = subscription
|
||||
}
|
||||
|
||||
this.subscriptions.sort((a, b) => {
|
||||
if (a.title && b.title) return a.title.localeCompare(b.title)
|
||||
return a.id - b.id
|
||||
})
|
||||
},
|
||||
async updateSubscriptionMeta(subscription) {
|
||||
try {
|
||||
const podcasts = await axios.get(generateUrl('/apps/gpoddersync/personal_settings/podcast_data?url={url}', { url: subscription.url }))
|
||||
this.addSubscription({ ...podcasts.data.data, ...subscription, ...{ loading: false } })
|
||||
} catch (e) {
|
||||
console.error(e)
|
||||
}
|
||||
},
|
||||
},
|
||||
}
|
||||
</script>
|
Loading…
Reference in New Issue
Block a user