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;
|
namespace OCA\RePod\AppInfo;
|
||||||
|
|
||||||
|
use OCP\App\AppPathNotFoundException;
|
||||||
use OCP\App\IAppManager;
|
use OCP\App\IAppManager;
|
||||||
use OCP\AppFramework\App;
|
use OCP\AppFramework\App;
|
||||||
use OCP\AppFramework\Bootstrap\IBootContext;
|
use OCP\AppFramework\Bootstrap\IBootContext;
|
||||||
use OCP\AppFramework\Bootstrap\IBootstrap;
|
use OCP\AppFramework\Bootstrap\IBootstrap;
|
||||||
use OCP\AppFramework\Bootstrap\IRegistrationContext;
|
use OCP\AppFramework\Bootstrap\IRegistrationContext;
|
||||||
use OCP\IUserSession;
|
use OCP\Server;
|
||||||
|
use OCP\Util;
|
||||||
|
|
||||||
class Application extends App implements IBootstrap
|
class Application extends App implements IBootstrap
|
||||||
{
|
{
|
||||||
@ -25,15 +27,33 @@ class Application extends App implements IBootstrap
|
|||||||
$appContainer = $context->getAppContainer();
|
$appContainer = $context->getAppContainer();
|
||||||
/** @var IAppManager $appManager */
|
/** @var IAppManager $appManager */
|
||||||
$appManager = $appContainer->get(IAppManager::class);
|
$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) {
|
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 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(
|
public function __construct(
|
||||||
IRequest $request,
|
IRequest $request,
|
||||||
private IClientService $clientService,
|
private IClientService $clientService,
|
||||||
private IFactory $l10nFactory,
|
private IFactory $l10n,
|
||||||
private IUserSession $userSession
|
private IUserSession $userSession
|
||||||
) {
|
) {
|
||||||
parent::__construct(Application::APP_ID, $request);
|
parent::__construct(Application::APP_ID, $request);
|
||||||
@ -35,7 +35,7 @@ class TopController extends Controller
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$lang = $this->l10nFactory->getUserLanguage($this->userSession->getUser());
|
$lang = $this->l10n->getUserLanguage($this->userSession->getUser());
|
||||||
$lang = explode('_', $lang);
|
$lang = explode('_', $lang);
|
||||||
$lang = count($lang) > 1 ? $lang[1] : $lang[0];
|
$lang = count($lang) > 1 ? $lang[1] : $lang[0];
|
||||||
$lang = $lang === 'en' ? 'us' : $lang;
|
$lang = $lang === 'en' ? 'us' : $lang;
|
||||||
@ -43,7 +43,7 @@ class TopController extends Controller
|
|||||||
$client = $this->clientService->newClient();
|
$client = $this->clientService->newClient();
|
||||||
$response = $client->get("https://rss.applemarketingtools.com/api/v2/{$lang}/podcasts/top/{$limit}/podcasts.json");
|
$response = $client->get("https://rss.applemarketingtools.com/api/v2/{$lang}/podcasts/top/{$limit}/podcasts.json");
|
||||||
/** @var array $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());
|
return new JSONResponse($json, $response->getStatusCode());
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
return new JSONResponse([$e->getMessage()], Http::STATUS_INTERNAL_SERVER_ERROR);
|
return new JSONResponse([$e->getMessage()], Http::STATUS_INTERNAL_SERVER_ERROR);
|
||||||
|
103
src/App.vue
103
src/App.vue
@ -1,111 +1,22 @@
|
|||||||
<template>
|
<template>
|
||||||
<NcContent app-name="repod">
|
<NcContent app-name="repod">
|
||||||
<NcAppNavigation>
|
<GPodder v-if="!AppConfig.repod.gpodder" />
|
||||||
<NcAppContentList>
|
<Index v-if="AppConfig.repod.gpodder" />
|
||||||
<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>
|
|
||||||
</NcContent>
|
</NcContent>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import '@nextcloud/dialogs/dist/index.css'
|
import '@nextcloud/dialogs/dist/index.css'
|
||||||
import {
|
import GPodder from './views/GPodder.vue'
|
||||||
NcAppContent,
|
import Index from './views/Index.vue'
|
||||||
NcAppContentList,
|
import { NcContent } from '@nextcloud/vue'
|
||||||
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'
|
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: 'App',
|
name: 'App',
|
||||||
components: {
|
components: {
|
||||||
NcAppContent,
|
GPodder,
|
||||||
NcAppContentList,
|
Index,
|
||||||
NcAppNavigation,
|
|
||||||
NcAppNavigationItem,
|
|
||||||
NcAppNavigationNew,
|
|
||||||
NcContent,
|
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>
|
</script>
|
||||||
|
@ -15,6 +15,8 @@ Vue.mixin({ methods: { t, n } })
|
|||||||
Vue.use(Plugin)
|
Vue.use(Plugin)
|
||||||
Vue.prototype.OC = window.OC
|
Vue.prototype.OC = window.OC
|
||||||
Vue.prototype.OCA = window.OCA
|
Vue.prototype.OCA = window.OCA
|
||||||
|
Vue.prototype.OCP = window.OCP
|
||||||
|
Vue.prototype.AppConfig = window.oc_appconfig
|
||||||
|
|
||||||
export default new Vue({
|
export default new Vue({
|
||||||
el: '#content',
|
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