Skip to content

Open-source download manager & offline media toolbox for YouTube, music, social media, learning platforms & 1,800+ sites. Built with Tauri 2.0, Rust & Svelte.

Remove Udemy and Voomp Play course pages and their associated logic

Tonho74ce07c7a862
diff --git a/src/components/hotmart/CourseCard.svelte b/src/components/hotmart/CourseCard.svelte
deleted file mode 100644
index a19bead1..00000000
--- a/src/components/hotmart/CourseCard.svelte
+++ /dev/null
@@ -1,309 +0,0 @@
-<script lang="ts">
- import { t } from "$lib/i18n";
-
- type CardDownloadStatus = "idle" | "downloading" | "complete" | "error";
-
- type CourseCardProps = {
- name: string;
- price: string;
- imageUrl?: string;
- externalPlatform?: boolean;
- downloadStatus?: CardDownloadStatus;
- downloadPercent?: number;
- onDownload: () => void;
- };
-
- let {
- name,
- price,
- imageUrl,
- externalPlatform = false,
- downloadStatus = "idle",
- downloadPercent = 0,
- onDownload,
- }: CourseCardProps = $props();
-
- let isDisabled = $derived(
- downloadStatus === "downloading" || downloadStatus === "complete"
- );
-
- function handleClick() {
- if (isDisabled) return;
- onDownload();
- }
-</script>
-
-<div class="course-card">
- <div class="card-image">
- {#if imageUrl}
- <img src={imageUrl} alt={name} loading="lazy" />
- {:else}
- <div class="card-placeholder">
- <svg
- width="48"
- height="48"
- viewBox="0 0 24 24"
- fill="none"
- stroke="currentColor"
- stroke-width="1.5"
- stroke-linecap="round"
- stroke-linejoin="round"
- >
- <path d="M22 9l-10 -4l-10 4l10 4l10 -4v6" />
- <path d="M6 10.6v5.4a6 3 0 0 0 12 0v-5.4" />
- </svg>
- </div>
- {/if}
- </div>
-
- <div class="card-body">
- <h4 class="card-title" title={name}>{name}</h4>
- <div class="card-meta">
- <span class="card-price">{price}</span>
- {#if externalPlatform}
- <span class="card-badge external">{$t("hotmart.external_platform")}</span>
- {/if}
- </div>
- {#if externalPlatform}
- <button class="button elevated card-download" disabled>
- <svg
- width="16"
- height="16"
- viewBox="0 0 24 24"
- fill="none"
- stroke="currentColor"
- stroke-width="2"
- stroke-linecap="round"
- stroke-linejoin="round"
- >
- <path d="M18 6L6 18M6 6l12 12" />
- </svg>
- {$t("hotmart.unavailable")}
- </button>
- {:else if downloadStatus === "downloading"}
- <button class="button elevated card-download status-downloading" disabled>
- <span class="btn-spinner"></span>
- {$t("hotmart.downloading")}
- </button>
- <div class="mini-progress-track">
- <div
- class="mini-progress-fill"
- style="width: {downloadPercent.toFixed(1)}%"
- ></div>
- </div>
- {:else if downloadStatus === "complete"}
- <button class="button elevated card-download status-complete" disabled>
- <svg
- width="16"
- height="16"
- viewBox="0 0 24 24"
- fill="none"
- stroke="currentColor"
- stroke-width="2"
- stroke-linecap="round"
- stroke-linejoin="round"
- >
- <path d="M5 12l5 5l10 -10" />
- </svg>
- {$t("hotmart.downloaded")}
- </button>
- {:else if downloadStatus === "error"}
- <button class="button elevated card-download status-error" onclick={handleClick}>
- <svg
- width="16"
- height="16"
- viewBox="0 0 24 24"
- fill="none"
- stroke="currentColor"
- stroke-width="2"
- stroke-linecap="round"
- stroke-linejoin="round"
- >
- <path d="M12 9v4" />
- <path d="M12 17h.01" />
- <path d="M3 12a9 9 0 1 0 18 0a9 9 0 0 0 -18 0" />
- </svg>
- {$t("hotmart.download_retry")}
- </button>
- {:else}
- <button class="button elevated card-download" onclick={handleClick}>
- <svg
- width="16"
- height="16"
- viewBox="0 0 24 24"
- fill="none"
- stroke="currentColor"
- stroke-width="2"
- stroke-linecap="round"
- stroke-linejoin="round"
- >
- <path d="M4 17v2a2 2 0 0 0 2 2h12a2 2 0 0 0 2 -2v-2" />
- <polyline points="7 11 12 16 17 11" />
- <line x1="12" y1="4" x2="12" y2="16" />
- </svg>
- {$t("hotmart.download_btn")}
- </button>
- {/if}
- </div>
-</div>
-
-<style>
- .course-card {
- background: var(--button);
- border-radius: var(--border-radius);
- box-shadow: var(--button-box-shadow);
- overflow: hidden;
- display: flex;
- flex-direction: column;
- }
-
- .card-image {
- width: 100%;
- aspect-ratio: 16 / 9;
- overflow: hidden;
- border-radius: var(--border-radius) var(--border-radius) 0 0;
- background: var(--button-elevated);
- }
-
- .card-image img {
- width: 100%;
- height: 100%;
- object-fit: cover;
- pointer-events: none;
- }
-
- .card-placeholder {
- width: 100%;
- height: 100%;
- display: flex;
- align-items: center;
- justify-content: center;
- }
-
- .card-placeholder svg {
- stroke: var(--gray);
- opacity: 0.5;
- pointer-events: none;
- }
-
- .card-body {
- padding: var(--padding);
- display: flex;
- flex-direction: column;
- gap: calc(var(--padding) / 2);
- }
-
- .card-title {
- font-size: 14.5px;
- font-weight: 500;
- margin-block: 0;
- display: -webkit-box;
- -webkit-line-clamp: 2;
- line-clamp: 2;
- -webkit-box-orient: vertical;
- overflow: hidden;
- text-overflow: ellipsis;
- line-height: 1.3;
- color: var(--secondary);
- user-select: text;
- }
-
- .card-meta {
- display: flex;
- align-items: center;
- gap: calc(var(--padding) / 2);
- flex-wrap: wrap;
- }
-
- .card-price {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .card-badge {
- font-size: 10px;
- font-weight: 500;
- text-transform: uppercase;
- letter-spacing: 0.04em;
- padding: 2px calc(var(--padding) / 2);
- border-radius: calc(var(--border-radius) / 2);
- }
-
- .card-badge.external {
- background: var(--orange);
- color: #000;
- }
-
- .card-download {
- width: 100%;
- display: flex;
- align-items: center;
- justify-content: center;
- gap: calc(var(--padding) / 2);
- margin-top: calc(var(--padding) / 2);
- }
-
- .card-download:disabled {
- opacity: 0.4;
- cursor: default;
- }
-
- .card-download svg {
- pointer-events: none;
- }
-
- .status-downloading {
- opacity: 0.8;
- cursor: default;
- }
-
- .status-downloading:disabled {
- opacity: 0.8;
- }
-
- .status-complete {
- background: var(--green);
- color: #000;
- }
-
- .status-complete:disabled {
- opacity: 1;
- }
-
- .status-error {
- background: var(--red);
- color: #fff;
- }
-
- .btn-spinner {
- width: 14px;
- height: 14px;
- border: 2px solid var(--input-border);
- border-top-color: var(--blue);
- border-radius: 50%;
- animation: spin 0.6s linear infinite;
- flex-shrink: 0;
- }
-
- @keyframes spin {
- to {
- transform: rotate(360deg);
- }
- }
-
- .mini-progress-track {
- width: 100%;
- height: 4px;
- background: var(--button-elevated);
- border-radius: 2px;
- overflow: hidden;
- }
-
- .mini-progress-fill {
- height: 100%;
- background: var(--blue);
- border-radius: 2px;
- transition: width 0.3s ease-out;
- }
-</style>
diff --git a/src/components/hotmart/ModuleList.svelte b/src/components/hotmart/ModuleList.svelte
deleted file mode 100644
index 9dcdf03b..00000000
--- a/src/components/hotmart/ModuleList.svelte
+++ /dev/null
@@ -1,73 +0,0 @@
-<script lang="ts">
- type Module = {
- id: string;
- name: string;
- pages: { hash: string; name: string; page_type: string }[];
- };
-
- let { modules }: { modules: Module[] } = $props();
-</script>
-
-<ul class="module-list">
- {#each modules as mod, i}
- <li class="module-item">
- <div class="module-header">
- <span class="module-number">{i + 1}.</span>
- <span class="module-name">{mod.name}</span>
- <span class="module-count">{mod.pages.length} {mod.pages.length === 1 ? 'aula' : 'aulas'}</span>
- </div>
- </li>
- {/each}
-</ul>
-
-<style>
- .module-list {
- list-style: none;
- padding: 0;
- margin: 0;
- display: flex;
- flex-direction: column;
- gap: 2px;
- }
-
- .module-item {
- padding: calc(var(--padding) / 1.5) var(--padding);
- border-radius: calc(var(--border-radius) - 4px);
- }
-
- @media (hover: hover) {
- .module-item:hover {
- background: var(--button-stroke);
- }
- }
-
- .module-header {
- display: flex;
- align-items: center;
- gap: calc(var(--padding) / 1.5);
- }
-
- .module-number {
- color: var(--gray);
- font-size: 12.5px;
- font-weight: 500;
- min-width: 22px;
- font-variant-numeric: tabular-nums;
- }
-
- .module-name {
- flex: 1;
- font-size: 14.5px;
- color: var(--secondary);
- }
-
- .module-count {
- font-size: 11px;
- font-weight: 500;
- color: var(--gray);
- background: var(--button-stroke);
- padding: 2px calc(var(--padding) / 2);
- border-radius: calc(var(--border-radius) / 2);
- white-space: nowrap;
- }
-</style>
diff --git a/src/lib/courses/platforms.ts b/src/lib/courses/platforms.ts
deleted file mode 100644
index 41dd836a..00000000
--- a/src/lib/courses/platforms.ts
+++ /dev/null
@@ -1,305 +0,0 @@
-export interface CoursePlatform {
- id: string;
- name: string;
- route: string;
- icon: string;
- color: string;
- enabled: boolean;
- authCheckCommand?: string;
-}
-
-export const COURSE_PLATFORMS: CoursePlatform[] = [
- {
- id: "hotmart",
- name: "Hotmart",
- route: "/courses/hotmart",
- icon: "hotmart",
- color: "#F04E23",
- enabled: true,
- authCheckCommand: "hotmart_check_session",
- },
- {
- id: "udemy",
- name: "Udemy",
- route: "/courses/udemy",
- icon: "udemy",
- color: "#A435F0",
- enabled: true,
- authCheckCommand: "udemy_check_session",
- },
- {
- id: "kiwify",
- name: "Kiwify",
- route: "/courses/kiwify",
- icon: "kiwify",
- color: "#22C55E",
- enabled: true,
- authCheckCommand: "kiwify_check_session",
- },
- {
- id: "gumroad",
- name: "Gumroad",
- route: "/courses/gumroad",
- icon: "gumroad",
- color: "#FF90E8",
- enabled: true,
- },
- {
- id: "teachable",
- name: "Teachable",
- route: "/courses/teachable",
- icon: "teachable",
- color: "#4B5563",
- enabled: true,
- },
- {
- id: "kajabi",
- name: "Kajabi",
- route: "/courses/kajabi",
- icon: "kajabi",
- color: "#2563EB",
- enabled: true,
- },
- {
- id: "skool",
- name: "Skool",
- route: "/courses/skool",
- icon: "skool",
- color: "#5865F2",
- enabled: true,
- },
- {
- id: "pluralsight",
- name: "Pluralsight",
- route: "/courses/pluralsight",
- icon: "pluralsight",
- color: "#E80A89",
- enabled: true,
- },
- {
- id: "greatcourses",
- name: "Wondrium",
- route: "/courses/greatcourses",
- icon: "greatcourses",
- color: "#1E3A5F",
- enabled: true,
- },
- {
- id: "masterclass",
- name: "MasterClass",
- route: "/courses/masterclass",
- icon: "masterclass",
- color: "#000000",
- enabled: true,
- },
- {
- id: "thinkific",
- name: "Thinkific",
- route: "/courses/thinkific",
- icon: "thinkific",
- color: "#4A90D9",
- enabled: true,
- authCheckCommand: "thinkific_check_session",
- },
- {
- id: "curseduca",
- name: "Curseduca",
- route: "/courses/curseduca",
- icon: "curseduca",
- color: "#6366F1",
- enabled: true,
- },
- {
- id: "cademi",
- name: "Cademi",
- route: "/courses/cademi",
- icon: "cademi",
- color: "#10B981",
- enabled: true,
- },
- {
- id: "cakto",
- name: "Cakto",
- route: "/courses/cakto",
- icon: "cakto",
- color: "#F59E0B",
- enabled: true,
- },
- {
- id: "kirvano",
- name: "Kirvano",
- route: "/courses/kirvano",
- icon: "kirvano",
- color: "#8B5CF6",
- enabled: true,
- },
- {
- id: "memberkit",
- name: "MemberKit",
- route: "/courses/memberkit",
- icon: "memberkit",
- color: "#3B82F6",
- enabled: true,
- },
- {
- id: "rocketseat",
- name: "Rocketseat",
- route: "/courses/rocketseat",
- icon: "rocketseat",
- color: "#8257E5",
- enabled: true,
- authCheckCommand: "rocketseat_check_session",
- },
- {
- id: "grancursos",
- name: "Gran Cursos",
- route: "/courses/grancursos",
- icon: "grancursos",
- color: "#1D4ED8",
- enabled: true,
- },
- {
- id: "fluencyacademy",
- name: "Fluency Academy",
- route: "/courses/fluencyacademy",
- icon: "fluencyacademy",
- color: "#F97316",
- enabled: true,
- },
- {
- id: "datascienceacademy",
- name: "Data Science Academy",
- route: "/courses/datascienceacademy",
- icon: "datascienceacademy",
- color: "#059669",
- enabled: true,
- },
- {
- id: "medcel",
- name: "Medcel",
- route: "/courses/medcel",
- icon: "medcel",
- color: "#DC2626",
- enabled: true,
- },
- {
- id: "medcof",
- name: "Medcof",
- route: "/courses/medcof",
- icon: "medcof",
- color: "#0891B2",
- enabled: true,
- },
- {
- id: "medway",
- name: "Medway",
- route: "/courses/medway",
- icon: "medway",
- color: "#7C3AED",
- enabled: true,
- },
- {
- id: "afyainternato",
- name: "Afya Internato",
- route: "/courses/afyainternato",
- icon: "afyainternato",
- color: "#EF4444",
- enabled: true,
- },
- {
- id: "alpaclass",
- name: "AlpaClass",
- route: "/courses/alpaclass",
- icon: "alpaclass",
- color: "#14B8A6",
- enabled: true,
- },
- {
- id: "areademembros",
- name: "Area de Membros",
- route: "/courses/areademembros",
- icon: "areademembros",
- color: "#6B7280",
- enabled: true,
- },
- {
- id: "astronmembers",
- name: "Astron Members",
- route: "/courses/astronmembers",
- icon: "astronmembers",
- color: "#1E40AF",
- enabled: true,
- },
- {
- id: "eduzznutror",
- name: "Eduzz / Nutror",
- route: "/courses/eduzznutror",
- icon: "eduzznutror",
- color: "#EA580C",
- enabled: true,
- },
- {
- id: "entregadigital",
- name: "Entrega Digital",
- route: "/courses/entregadigital",
- icon: "entregadigital",
- color: "#4338CA",
- enabled: true,
- },
- {
- id: "greennclub",
- name: "Greenn Club",
- route: "/courses/greennclub",
- icon: "greennclub",
- color: "#16A34A",
- enabled: true,
- },
- {
- id: "themembers",
- name: "TheMembers",
- route: "/courses/themembers",
- icon: "themembers",
- color: "#9333EA",
- enabled: true,
- },
- {
- id: "voompplay",
- name: "Voomp Play",
- route: "/courses/voompplay",
- icon: "voompplay",
- color: "#0EA5E9",
- enabled: true,
- },
- {
- id: "estrategia_concursos",
- name: "Estratégia Concursos",
- route: "/courses/estrategia-concursos",
- icon: "estrategia",
- color: "#1E3A8A",
- enabled: true,
- },
- {
- id: "estrategia_ldi",
- name: "Estratégia LDI",
- route: "/courses/estrategia-ldi",
- icon: "estrategia",
- color: "#1E40AF",
- enabled: true,
- },
- {
- id: "estrategia_militares",
- name: "Estratégia Militares",
- route: "/courses/estrategia-militares",
- icon: "estrategia",
- color: "#15803D",
- enabled: true,
- },
- {
- id: "caktomembers",
- name: "Cakto Members",
- route: "/courses/caktomembers",
- icon: "cakto",
- color: "#D97706",
- enabled: true,
- },
-];
diff --git a/src/routes/courses/+layout.svelte b/src/routes/courses/+layout.svelte
deleted file mode 100644
index 5dd96809..00000000
--- a/src/routes/courses/+layout.svelte
+++ /dev/null
@@ -1,6 +0,0 @@
-<script lang="ts">
- import type { Snippet } from "svelte";
- let { children }: { children: Snippet } = $props();
-</script>
-
-{@render children()}
diff --git a/src/routes/courses/afyainternato/+page.svelte b/src/routes/courses/afyainternato/+page.svelte
deleted file mode 100644
index 9d297ff7..00000000
--- a/src/routes/courses/afyainternato/+page.svelte
+++ /dev/null
@@ -1,725 +0,0 @@
-<script lang="ts">
- import { pluginInvoke } from "$lib/plugin-invoke";
- import { open } from "@tauri-apps/plugin-dialog";
- import CourseCard from "$components/hotmart/CourseCard.svelte";
- import { showToast } from "$lib/stores/toast-store.svelte";
- import { getDownloads } from "$lib/stores/download-store.svelte";
- import { getSettings } from "$lib/stores/settings-store.svelte";
- import { t } from "$lib/i18n";
-
- let downloads = $derived(getDownloads());
-
- type AfyaCourse = {
- id: string;
- name: string;
- product_id: string;
- };
-
- let email = $state("");
- let password = $state("");
- let apiKey = $state("");
- let token = $state("");
- let tokenApiKey = $state("");
- let loading = $state(false);
- let error = $state("");
-
- let checking = $state(true);
- let loggedIn = $state(false);
- let sessionEmail = $state("");
-
- let loginMode = $state<"credentials" | "token">("credentials");
-
- let fileInput: HTMLInputElement = $state() as HTMLInputElement;
-
- function onFileSelected(e: Event) {
- const input = e.target as HTMLInputElement;
- const file = input.files?.[0];
- if (!file) return;
- const reader = new FileReader();
- reader.onload = () => { token = reader.result as string; };
- reader.readAsText(file);
- input.value = "";
- }
-
- let courses: AfyaCourse[] = $state([]);
- let loadingCourses = $state(false);
- let coursesError = $state("");
-
- const ITEMS_PER_PAGE = 12;
- let currentPage = $state(1);
-
- let totalPages = $derived(Math.max(1, Math.ceil(courses.length / ITEMS_PER_PAGE)));
- let paginatedCourses = $derived(
- courses.slice((currentPage - 1) * ITEMS_PER_PAGE, currentPage * ITEMS_PER_PAGE)
- );
-
- let pageNumbers = $derived((): number[] => {
- const pages: number[] = [];
- if (totalPages <= 7) {
- for (let i = 1; i <= totalPages; i++) pages.push(i);
- } else {
- pages.push(1);
- if (currentPage > 3) pages.push(-1);
- const start = Math.max(2, currentPage - 1);
- const end = Math.min(totalPages - 1, currentPage + 1);
- for (let i = start; i <= end; i++) pages.push(i);
- if (currentPage < totalPages - 2) pages.push(-1);
- pages.push(totalPages);
- }
- return pages;
- });
-
- function goToPage(page: number) {
- if (page >= 1 && page <= totalPages) {
- currentPage = page;
- }
- }
-
- $effect(() => {
- checkSession();
- });
-
- async function checkSession() {
- try {
- const result = await pluginInvoke<string>("courses", "afya_check_session");
- sessionEmail = result;
- loggedIn = true;
- loadCourses();
- } catch {
- loggedIn = false;
- } finally {
- checking = false;
- }
- }
-
- async function handleLogin() {
- error = "";
- loading = true;
- try {
- const result = await pluginInvoke<string>("courses", "afya_login", { email, password, apiKey });
- sessionEmail = result || email;
- loggedIn = true;
- loadCourses();
- } catch (e: any) {
- error = typeof e === "string" ? e : e.message ?? $t('hotmart.unknown_error');
- } finally {
- loading = false;
- }
- }
-
- async function handleTokenLogin() {
- if (!token.trim()) return;
- error = "";
- loading = true;
- try {
- const result = await pluginInvoke<string>("courses", "afya_login_token", { token: token.trim(), apiKey: tokenApiKey.trim() });
- sessionEmail = result || "Token";
- loggedIn = true;
- loadCourses();
- } catch (e: any) {
- error = typeof e === "string" ? e : e.message ?? $t('hotmart.unknown_error');
- } finally {
- loading = false;
- }
- }
-
- async function handleLogout() {
- try {
- await pluginInvoke("courses", "afya_logout");
- } catch {
- }
- loggedIn = false;
- sessionEmail = "";
- courses = [];
- coursesError = "";
- currentPage = 1;
- }
-
- async function loadCourses() {
- loadingCourses = true;
- coursesError = "";
- try {
- courses = await pluginInvoke("courses", "afya_list_courses");
- currentPage = 1;
- } catch (e: any) {
- coursesError = typeof e === "string" ? e : e.message ?? $t('hotmart.courses_error');
- } finally {
- loadingCourses = false;
- }
- }
-
- function getCourseDownloadStatus(courseId: number): "idle" | "downloading" | "complete" | "error" {
- const item = downloads.get(courseId);
- if (!item) return "idle";
- const s = item.status;
- if (s === "queued" || s === "paused" || s === "seeding") return "downloading";
- return s;
- }
-
- function getCourseDownloadPercent(courseId: number): number {
- return downloads.get(courseId)?.percent ?? 0;
- }
-
- async function downloadCourse(course: AfyaCourse) {
- const status = getCourseDownloadStatus(Number(course.id) || 0);
- if (status === "downloading") {
- showToast("info", $t("toast.download_already_active"));
- return;
- }
- if (status === "complete") return;
-
- const appSettings = getSettings();
- let outputDir: string | null = null;
-
- if (appSettings?.download.always_ask_path) {
- outputDir = await open({ directory: true, title: $t("hotmart.choose_folder") }) as string | null;
- if (!outputDir) return;
- } else {
- outputDir = appSettings?.download.default_output_dir ?? null;
- if (!outputDir) {
- outputDir = await open({ directory: true, title: $t("hotmart.choose_folder") }) as string | null;
- if (!outputDir) return;
- }
- }
-
- try {
- await pluginInvoke("courses", "start_afya_course_download", {
- courseJson: JSON.stringify(course),
- outputDir,
- });
- showToast("info", $t("toast.download_preparing"));
- } catch (e: any) {
- const msg = typeof e === "string" ? e : e.message ?? $t("common.error");
- showToast("error", msg);
- }
- }
-
- let refreshing = $state(false);
-
- async function refreshCourses() {
- refreshing = true;
- loadingCourses = true;
- coursesError = "";
- try {
- courses = await pluginInvoke("courses", "afya_refresh_courses");
- currentPage = 1;
- } catch (e: any) {
- coursesError = typeof e === "string" ? e : e.message ?? $t('hotmart.courses_error');
- } finally {
- loadingCourses = false;
- refreshing = false;
- }
- }
-</script>
-
-<a href="/courses" class="back-link">
- <svg viewBox="0 0 24 24" width="16" height="16" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
- <path d="M19 12H5" />
- <path d="M12 19l-7-7 7-7" />
- </svg>
- {$t("courses.back")}
-</a>
-
-{#if checking}
- <div class="page-center">
- <span class="spinner"></span>
- <span class="spinner-text">{$t('hotmart.checking_session')}</span>
- </div>
-{:else if loggedIn}
- <div class="page-logged">
- <div class="session-bar">
- <span class="session-info">
- {$t('hotmart.logged_as', { email: sessionEmail || "\u2014" })}
- </span>
- <div class="session-actions">
- <button
- class="button"
- onclick={refreshCourses}
- disabled={refreshing}
- aria-label={$t('hotmart.refresh')}
- >
- <svg viewBox="0 0 24 24" width="14" height="14" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class:spinning={refreshing}>
- <path d="M21 2v6h-6" />
- <path d="M3 12a9 9 0 0115-6.7L21 8" />
- <path d="M3 22v-6h6" />
- <path d="M21 12a9 9 0 01-15 6.7L3 16" />
- </svg>
- </button>
- <button class="button" onclick={handleLogout}>{$t('hotmart.logout')}</button>
- </div>
- </div>
-
- {#if loadingCourses}
- <div class="spinner-section">
- <span class="spinner"></span>
- <span class="spinner-text">{$t('hotmart.loading_courses')}</span>
- </div>
- {:else if coursesError}
- <div class="error-section">
- <p class="error-msg">{coursesError}</p>
- <button class="button" onclick={loadCourses}>{$t('common.retry')}</button>
- </div>
- {:else if courses.length === 0}
- <p class="empty-text">{$t('hotmart.no_courses')}</p>
- {:else}
- <div class="courses-header">
- <h2>{$t('hotmart.courses_title')}</h2>
- <span class="subtext">{courses.length === 1 ? $t('hotmart.course_count_one', { count: courses.length }) : $t('hotmart.course_count', { count: courses.length })}</span>
- </div>
-
- <div class="courses-grid">
- {#each paginatedCourses as course (course.id)}
- <CourseCard
- name={course.name}
- price={course.product_id}
- downloadStatus={getCourseDownloadStatus(Number(course.id) || 0)}
- downloadPercent={getCourseDownloadPercent(Number(course.id) || 0)}
- onDownload={() => downloadCourse(course)}
- />
- {/each}
- </div>
-
- {#if totalPages > 1}
- <div class="pagination">
- <span class="pagination-info">
- {$t('hotmart.page_of', { current: currentPage, total: totalPages })} &middot; {courses.length === 1 ? $t('hotmart.course_count_one', { count: courses.length }) : $t('hotmart.course_count', { count: courses.length })}
- </span>
- <div class="pagination-controls">
- <button
- class="button pagination-btn"
- disabled={currentPage <= 1}
- onclick={() => goToPage(currentPage - 1)}
- >
- &lt;
- </button>
-
- {#each pageNumbers() as page}
- {#if page === -1}
- <span class="pagination-ellipsis">&hellip;</span>
- {:else}
- <button
- class="button pagination-btn"
- class:active={page === currentPage}
- onclick={() => goToPage(page)}
- >
- {page}
- </button>
- {/if}
- {/each}
-
- <button
- class="button pagination-btn"
- disabled={currentPage >= totalPages}
- onclick={() => goToPage(currentPage + 1)}
- >
- &gt;
- </button>
- </div>
- </div>
- {/if}
- {/if}
- </div>
-{:else}
- <div class="page-center">
- <div class="login-card">
- <h2>Afya Internato</h2>
-
- <div class="login-tabs">
- <button
- class="button login-tab"
- class:active={loginMode === "credentials"}
- onclick={() => { loginMode = "credentials"; error = ""; }}
- >
- Email & Password
- </button>
- <button
- class="button login-tab"
- class:active={loginMode === "token"}
- onclick={() => { loginMode = "token"; error = ""; }}
- >
- Token
- </button>
- </div>
-
- {#if loginMode === "credentials"}
- <form class="form" onsubmit={(e) => { e.preventDefault(); handleLogin(); }}>
- <label class="field">
- <span class="field-label">{$t('hotmart.email_label')}</span>
- <input
- type="email"
- placeholder={$t('hotmart.email_placeholder')}
- bind:value={email}
- class="input"
- disabled={loading}
- required
- />
- </label>
- <label class="field">
- <span class="field-label">{$t('hotmart.password_label')}</span>
- <input
- type="password"
- placeholder={$t('hotmart.password_placeholder')}
- bind:value={password}
- class="input"
- disabled={loading}
- required
- />
- </label>
- <label class="field">
- <span class="field-label">API Key</span>
- <input
- type="text"
- placeholder="Paste your API key here..."
- bind:value={apiKey}
- class="input"
- disabled={loading}
- required
- />
- </label>
-
- {#if error}
- <p class="error-msg">{error}</p>
- {/if}
-
- <button type="submit" class="button" disabled={loading}>
- {#if loading}
- {$t('hotmart.authenticating')}
- {:else}
- {$t('hotmart.login')}
- {/if}
- </button>
- </form>
- {:else}
- <div class="form">
- <label class="field">
- <span class="field-label">Cookies JSON</span>
- <textarea
- class="input token-textarea"
- placeholder="Paste cookies JSON from browser extension or a raw token"
- bind:value={token}
- disabled={loading}
- rows="5"
- ></textarea>
- </label>
-
- <input
- type="file"
- accept=".json,.txt"
- class="hidden-file-input"
- bind:this={fileInput}
- onchange={onFileSelected}
- />
- <button class="button" onclick={() => fileInput?.click()} disabled={loading}>
- Import .json file
- </button>
-
- <label class="field">
- <span class="field-label">API Key</span>
- <input
- type="text"
- placeholder="Paste your API key here..."
- bind:value={tokenApiKey}
- class="input"
- disabled={loading}
- />
- </label>
-
- {#if error}
- <p class="error-msg">{error}</p>
- {/if}
-
- <button class="button" onclick={handleTokenLogin} disabled={loading || !token.trim()}>
- {#if loading}
- {$t('hotmart.authenticating')}
- {:else}
- {$t('hotmart.login')}
- {/if}
- </button>
- </div>
- {/if}
- </div>
- </div>
-{/if}
-
-<style>
- .back-link {
- display: inline-flex;
- align-items: center;
- gap: 6px;
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- margin-bottom: var(--padding);
- }
-
- @media (hover: hover) {
- .back-link:hover {
- color: var(--secondary);
- }
- }
-
- .page-center {
- display: flex;
- flex-direction: column;
- align-items: center;
- justify-content: center;
- min-height: calc(100vh - var(--padding) * 4 - 40px);
- gap: var(--padding);
- }
-
- .page-logged {
- display: flex;
- flex-direction: column;
- align-items: center;
- gap: calc(var(--padding) * 1.5);
- padding: calc(var(--padding) * 1.5);
- width: 100%;
- }
-
- .page-logged > :global(*) {
- width: 100%;
- max-width: 1200px;
- }
-
- .session-bar {
- display: flex;
- align-items: center;
- justify-content: space-between;
- }
-
- .session-info {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .session-actions {
- display: flex;
- gap: calc(var(--padding) / 2);
- }
-
- .session-bar :global(.button) {
- padding: calc(var(--padding) / 2) var(--padding);
- font-size: 12.5px;
- }
-
- .spinning {
- animation: spin 0.6s linear infinite;
- }
-
- .courses-header {
- display: flex;
- align-items: baseline;
- gap: var(--padding);
- }
-
- .courses-header h2 {
- margin-block: 0;
- }
-
- .subtext {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .courses-grid {
- display: grid;
- grid-template-columns: repeat(4, 1fr);
- gap: var(--padding);
- }
-
- @media (max-width: 1000px) {
- .courses-grid {
- grid-template-columns: repeat(3, 1fr);
- }
- }
-
- @media (max-width: 750px) {
- .courses-grid {
- grid-template-columns: repeat(2, 1fr);
- }
- }
-
- @media (max-width: 535px) {
- .courses-grid {
- grid-template-columns: 1fr;
- }
- }
-
- .pagination {
- display: flex;
- flex-direction: column;
- align-items: center;
- gap: var(--padding);
- padding-top: var(--padding);
- }
-
- .pagination-info {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .pagination-controls {
- display: flex;
- align-items: center;
- gap: calc(var(--padding) / 3);
- }
-
- .pagination-btn {
- min-width: 36px;
- height: 36px;
- padding: 0;
- display: flex;
- align-items: center;
- justify-content: center;
- font-size: 14.5px;
- }
-
- .pagination-ellipsis {
- min-width: 36px;
- text-align: center;
- color: var(--gray);
- font-size: 14.5px;
- }
-
- .login-card {
- width: 100%;
- max-width: 400px;
- background: var(--button-elevated);
- border-radius: var(--border-radius);
- padding: calc(var(--padding) * 2);
- display: flex;
- flex-direction: column;
- gap: calc(var(--padding) * 1.5);
- }
-
- .login-card h2 {
- margin-block: 0;
- }
-
- .login-tabs {
- display: flex;
- gap: 0;
- }
-
- .login-tab {
- flex: 1;
- border-radius: 0;
- font-size: 12.5px;
- padding: calc(var(--padding) * 0.75) var(--padding);
- }
-
- .login-tab:first-child {
- border-radius: var(--border-radius) 0 0 var(--border-radius);
- }
-
- .login-tab:last-child {
- border-radius: 0 var(--border-radius) var(--border-radius) 0;
- }
-
- .hidden-file-input {
- display: none;
- }
-
- .token-textarea {
- resize: vertical;
- min-height: 80px;
- font-size: 11.5px;
- font-family: var(--font-mono);
- line-height: 1.5;
- }
-
- .form {
- display: flex;
- flex-direction: column;
- gap: var(--padding);
- }
-
- .field {
- display: flex;
- flex-direction: column;
- gap: calc(var(--padding) / 2);
- }
-
- .field-label {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .input {
- width: 100%;
- padding: var(--padding);
- font-size: 14.5px;
- background: var(--button);
- border-radius: var(--border-radius);
- color: var(--secondary);
- border: 1px solid var(--input-border);
- }
-
- .input::placeholder {
- color: var(--gray);
- }
-
- .input:focus-visible {
- border-color: var(--secondary);
- outline: none;
- }
-
- .input:disabled {
- opacity: 0.5;
- cursor: default;
- }
-
- .error-msg {
- color: var(--red);
- font-size: 12.5px;
- font-weight: 500;
- }
-
- .spinner-section {
- display: flex;
- flex-direction: column;
- align-items: center;
- gap: var(--padding);
- padding: calc(var(--padding) * 4) 0;
- }
-
- .spinner {
- width: 24px;
- height: 24px;
- border: 2px solid var(--input-border);
- border-top-color: var(--blue);
- border-radius: 50%;
- animation: spin 0.6s linear infinite;
- }
-
- @keyframes spin {
- to {
- transform: rotate(360deg);
- }
- }
-
- .spinner-text {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .error-section {
- display: flex;
- flex-direction: column;
- align-items: center;
- gap: var(--padding);
- padding: calc(var(--padding) * 2) 0;
- }
-
- .empty-text {
- color: var(--gray);
- font-size: 14.5px;
- text-align: center;
- padding: calc(var(--padding) * 4) 0;
- }
-</style>
diff --git a/src/routes/courses/alpaclass/+page.svelte b/src/routes/courses/alpaclass/+page.svelte
deleted file mode 100644
index ac74cd52..00000000
--- a/src/routes/courses/alpaclass/+page.svelte
+++ /dev/null
@@ -1,616 +0,0 @@
-<script lang="ts">
- import { pluginInvoke } from "$lib/plugin-invoke";
- import { open } from "@tauri-apps/plugin-dialog";
- import CourseCard from "$components/hotmart/CourseCard.svelte";
- import { showToast } from "$lib/stores/toast-store.svelte";
- import { getDownloads } from "$lib/stores/download-store.svelte";
- import { getSettings } from "$lib/stores/settings-store.svelte";
- import { t } from "$lib/i18n";
-
- let downloads = $derived(getDownloads());
-
- type AlpaclassCourse = {
- slug: string;
- name: string;
- author: string;
- };
-
- let token = $state("");
- let platformUrl = $state("");
- let loading = $state(false);
- let error = $state("");
-
- let fileInput: HTMLInputElement = $state() as HTMLInputElement;
-
- function onFileSelected(e: Event) {
- const input = e.target as HTMLInputElement;
- const file = input.files?.[0];
- if (!file) return;
- const reader = new FileReader();
- reader.onload = () => { token = reader.result as string; };
- reader.readAsText(file);
- input.value = "";
- }
-
- let checking = $state(true);
- let loggedIn = $state(false);
- let sessionEmail = $state("");
-
- let courses: AlpaclassCourse[] = $state([]);
- let loadingCourses = $state(false);
- let coursesError = $state("");
-
- const ITEMS_PER_PAGE = 12;
- let currentPage = $state(1);
-
- let totalPages = $derived(Math.max(1, Math.ceil(courses.length / ITEMS_PER_PAGE)));
- let paginatedCourses = $derived(
- courses.slice((currentPage - 1) * ITEMS_PER_PAGE, currentPage * ITEMS_PER_PAGE)
- );
-
- let pageNumbers = $derived((): number[] => {
- const pages: number[] = [];
- if (totalPages <= 7) {
- for (let i = 1; i <= totalPages; i++) pages.push(i);
- } else {
- pages.push(1);
- if (currentPage > 3) pages.push(-1);
- const start = Math.max(2, currentPage - 1);
- const end = Math.min(totalPages - 1, currentPage + 1);
- for (let i = start; i <= end; i++) pages.push(i);
- if (currentPage < totalPages - 2) pages.push(-1);
- pages.push(totalPages);
- }
- return pages;
- });
-
- function goToPage(page: number) {
- if (page >= 1 && page <= totalPages) {
- currentPage = page;
- }
- }
-
- $effect(() => {
- checkSession();
- });
-
- async function checkSession() {
- try {
- const result = await pluginInvoke<string>("courses", "alpaclass_check_session");
- sessionEmail = result;
- loggedIn = true;
- loadCourses();
- } catch {
- loggedIn = false;
- } finally {
- checking = false;
- }
- }
-
- async function handleTokenLogin() {
- if (!token.trim()) return;
- error = "";
- loading = true;
- try {
- const result = await pluginInvoke<string>("courses", "alpaclass_login", {
- token: token.trim(),
- platformUrl: platformUrl.trim(),
- });
- sessionEmail = result || "Token";
- loggedIn = true;
- loadCourses();
- } catch (e: any) {
- error = typeof e === "string" ? e : e.message ?? $t('hotmart.unknown_error');
- } finally {
- loading = false;
- }
- }
-
- async function handleLogout() {
- try {
- await pluginInvoke("courses", "alpaclass_logout");
- } catch {
- }
- loggedIn = false;
- sessionEmail = "";
- courses = [];
- coursesError = "";
- currentPage = 1;
- }
-
- async function loadCourses() {
- loadingCourses = true;
- coursesError = "";
- try {
- courses = await pluginInvoke("courses", "alpaclass_list_courses");
- currentPage = 1;
- } catch (e: any) {
- coursesError = typeof e === "string" ? e : e.message ?? $t('hotmart.courses_error');
- } finally {
- loadingCourses = false;
- }
- }
-
- function getCourseDownloadStatus(_courseSlug: string): "idle" | "downloading" | "complete" | "error" {
- return "idle";
- }
-
- function getCourseDownloadPercent(_courseSlug: string): number {
- return 0;
- }
-
- async function downloadCourse(course: AlpaclassCourse) {
- const status = getCourseDownloadStatus(course.slug);
- if (status === "downloading") {
- showToast("info", $t("toast.download_already_active"));
- return;
- }
- if (status === "complete") return;
-
- const appSettings = getSettings();
- let outputDir: string | null = null;
-
- if (appSettings?.download.always_ask_path) {
- outputDir = await open({ directory: true, title: $t("hotmart.choose_folder") }) as string | null;
- if (!outputDir) return;
- } else {
- outputDir = appSettings?.download.default_output_dir ?? null;
- if (!outputDir) {
- outputDir = await open({ directory: true, title: $t("hotmart.choose_folder") }) as string | null;
- if (!outputDir) return;
- }
- }
-
- try {
- await pluginInvoke("courses", "start_alpaclass_course_download", {
- courseJson: JSON.stringify(course),
- outputDir,
- });
- showToast("info", $t("toast.download_preparing"));
- } catch (e: any) {
- const msg = typeof e === "string" ? e : e.message ?? $t("common.error");
- showToast("error", msg);
- }
- }
-
- let refreshing = $state(false);
-
- async function refreshCourses() {
- refreshing = true;
- loadingCourses = true;
- coursesError = "";
- try {
- courses = await pluginInvoke("courses", "alpaclass_refresh_courses");
- currentPage = 1;
- } catch (e: any) {
- coursesError = typeof e === "string" ? e : e.message ?? $t('hotmart.courses_error');
- } finally {
- loadingCourses = false;
- refreshing = false;
- }
- }
-</script>
-
-<a href="/courses" class="back-link">
- <svg viewBox="0 0 24 24" width="16" height="16" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
- <path d="M19 12H5" />
- <path d="M12 19l-7-7 7-7" />
- </svg>
- {$t("courses.back")}
-</a>
-
-{#if checking}
- <div class="page-center">
- <span class="spinner"></span>
- <span class="spinner-text">{$t('hotmart.checking_session')}</span>
- </div>
-{:else if loggedIn}
- <div class="page-logged">
- <div class="session-bar">
- <span class="session-info">
- {$t('hotmart.logged_as', { email: sessionEmail || "—" })}
- </span>
- <div class="session-actions">
- <button
- class="button"
- onclick={refreshCourses}
- disabled={refreshing}
- aria-label={$t('hotmart.refresh')}
- >
- <svg viewBox="0 0 24 24" width="14" height="14" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class:spinning={refreshing}>
- <path d="M21 2v6h-6" />
- <path d="M3 12a9 9 0 0115-6.7L21 8" />
- <path d="M3 22v-6h6" />
- <path d="M21 12a9 9 0 01-15 6.7L3 16" />
- </svg>
- </button>
- <button class="button" onclick={handleLogout}>{$t('hotmart.logout')}</button>
- </div>
- </div>
-
- {#if loadingCourses}
- <div class="spinner-section">
- <span class="spinner"></span>
- <span class="spinner-text">{$t('hotmart.loading_courses')}</span>
- </div>
- {:else if coursesError}
- <div class="error-section">
- <p class="error-msg">{coursesError}</p>
- <button class="button" onclick={loadCourses}>{$t('common.retry')}</button>
- </div>
- {:else if courses.length === 0}
- <p class="empty-text">{$t('hotmart.no_courses')}</p>
- {:else}
- <div class="courses-header">
- <h2>{$t('hotmart.courses_title')}</h2>
- <span class="subtext">{courses.length === 1 ? $t('hotmart.course_count_one', { count: courses.length }) : $t('hotmart.course_count', { count: courses.length })}</span>
- </div>
-
- <div class="courses-grid">
- {#each paginatedCourses as course (course.slug)}
- <CourseCard
- name={course.name}
- price={course.author}
- downloadStatus={getCourseDownloadStatus(course.slug)}
- downloadPercent={getCourseDownloadPercent(course.slug)}
- onDownload={() => downloadCourse(course)}
- />
- {/each}
- </div>
-
- {#if totalPages > 1}
- <div class="pagination">
- <span class="pagination-info">
- {$t('hotmart.page_of', { current: currentPage, total: totalPages })} &middot; {courses.length === 1 ? $t('hotmart.course_count_one', { count: courses.length }) : $t('hotmart.course_count', { count: courses.length })}
- </span>
- <div class="pagination-controls">
- <button
- class="button pagination-btn"
- disabled={currentPage <= 1}
- onclick={() => goToPage(currentPage - 1)}
- >
- &lt;
- </button>
-
- {#each pageNumbers() as page}
- {#if page === -1}
- <span class="pagination-ellipsis">&hellip;</span>
- {:else}
- <button
- class="button pagination-btn"
- class:active={page === currentPage}
- onclick={() => goToPage(page)}
- >
- {page}
- </button>
- {/if}
- {/each}
-
- <button
- class="button pagination-btn"
- disabled={currentPage >= totalPages}
- onclick={() => goToPage(currentPage + 1)}
- >
- &gt;
- </button>
- </div>
- </div>
- {/if}
- {/if}
- </div>
-{:else}
- <div class="page-center">
- <div class="login-card">
- <h2>AlpaClass</h2>
-
- <div class="form">
- <label class="field">
- <span class="field-label">Platform URL</span>
- <input
- type="url"
- placeholder="https://example.alpaclass.com"
- bind:value={platformUrl}
- class="input"
- disabled={loading}
- />
- </label>
- <label class="field">
- <span class="field-label">Cookies JSON</span>
- <textarea
- class="input token-textarea"
- placeholder="Paste cookies JSON from browser extension or a raw token"
- bind:value={token}
- disabled={loading}
- rows="5"
- ></textarea>
- </label>
-
- <input
- type="file"
- accept=".json,.txt"
- class="hidden-file-input"
- bind:this={fileInput}
- onchange={onFileSelected}
- />
- <button class="button" onclick={() => fileInput?.click()} disabled={loading}>
- Import .json file
- </button>
-
- {#if error}
- <p class="error-msg">{error}</p>
- {/if}
-
- <button class="button" onclick={handleTokenLogin} disabled={loading || !token.trim()}>
- {#if loading}
- {$t('hotmart.authenticating')}
- {:else}
- {$t('hotmart.login')}
- {/if}
- </button>
- </div>
- </div>
- </div>
-{/if}
-
-<style>
- .back-link {
- display: inline-flex;
- align-items: center;
- gap: 6px;
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- margin-bottom: var(--padding);
- }
-
- @media (hover: hover) {
- .back-link:hover {
- color: var(--secondary);
- }
- }
-
- .page-center {
- display: flex;
- flex-direction: column;
- align-items: center;
- justify-content: center;
- min-height: calc(100vh - var(--padding) * 4 - 40px);
- gap: var(--padding);
- }
-
- .page-logged {
- display: flex;
- flex-direction: column;
- align-items: center;
- gap: calc(var(--padding) * 1.5);
- padding: calc(var(--padding) * 1.5);
- width: 100%;
- }
-
- .page-logged > :global(*) {
- width: 100%;
- max-width: 1200px;
- }
-
- .session-bar {
- display: flex;
- align-items: center;
- justify-content: space-between;
- }
-
- .session-info {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .session-actions {
- display: flex;
- gap: calc(var(--padding) / 2);
- }
-
- .session-bar :global(.button) {
- padding: calc(var(--padding) / 2) var(--padding);
- font-size: 12.5px;
- }
-
- .spinning {
- animation: spin 0.6s linear infinite;
- }
-
- .courses-header {
- display: flex;
- align-items: baseline;
- gap: var(--padding);
- }
-
- .courses-header h2 {
- margin-block: 0;
- }
-
- .subtext {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .courses-grid {
- display: grid;
- grid-template-columns: repeat(4, 1fr);
- gap: var(--padding);
- }
-
- @media (max-width: 1000px) {
- .courses-grid {
- grid-template-columns: repeat(3, 1fr);
- }
- }
-
- @media (max-width: 750px) {
- .courses-grid {
- grid-template-columns: repeat(2, 1fr);
- }
- }
-
- @media (max-width: 535px) {
- .courses-grid {
- grid-template-columns: 1fr;
- }
- }
-
- .pagination {
- display: flex;
- flex-direction: column;
- align-items: center;
- gap: var(--padding);
- padding-top: var(--padding);
- }
-
- .pagination-info {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .pagination-controls {
- display: flex;
- align-items: center;
- gap: calc(var(--padding) / 3);
- }
-
- .pagination-btn {
- min-width: 36px;
- height: 36px;
- padding: 0;
- display: flex;
- align-items: center;
- justify-content: center;
- font-size: 14.5px;
- }
-
- .pagination-ellipsis {
- min-width: 36px;
- text-align: center;
- color: var(--gray);
- font-size: 14.5px;
- }
-
- .login-card {
- width: 100%;
- max-width: 400px;
- background: var(--button-elevated);
- border-radius: var(--border-radius);
- padding: calc(var(--padding) * 2);
- display: flex;
- flex-direction: column;
- gap: calc(var(--padding) * 1.5);
- }
-
- .login-card h2 {
- margin-block: 0;
- }
-
- .hidden-file-input {
- display: none;
- }
-
- .token-textarea {
- resize: vertical;
- min-height: 80px;
- font-size: 11.5px;
- font-family: var(--font-mono);
- line-height: 1.5;
- }
-
- .form {
- display: flex;
- flex-direction: column;
- gap: var(--padding);
- }
-
- .field {
- display: flex;
- flex-direction: column;
- gap: calc(var(--padding) / 2);
- }
-
- .field-label {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .input {
- width: 100%;
- padding: var(--padding);
- font-size: 14.5px;
- background: var(--button);
- border-radius: var(--border-radius);
- color: var(--secondary);
- border: 1px solid var(--input-border);
- }
-
- .input::placeholder {
- color: var(--gray);
- }
-
- .input:focus-visible {
- border-color: var(--secondary);
- outline: none;
- }
-
- .input:disabled {
- opacity: 0.5;
- cursor: default;
- }
-
- .error-msg {
- color: var(--red);
- font-size: 12.5px;
- font-weight: 500;
- }
-
- .spinner-section {
- display: flex;
- flex-direction: column;
- align-items: center;
- gap: var(--padding);
- padding: calc(var(--padding) * 4) 0;
- }
-
- .spinner {
- width: 24px;
- height: 24px;
- border: 2px solid var(--input-border);
- border-top-color: var(--blue);
- border-radius: 50%;
- animation: spin 0.6s linear infinite;
- }
-
- @keyframes spin {
- to {
- transform: rotate(360deg);
- }
- }
-
- .spinner-text {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .error-section {
- display: flex;
- flex-direction: column;
- align-items: center;
- gap: var(--padding);
- padding: calc(var(--padding) * 2) 0;
- }
-
- .empty-text {
- color: var(--gray);
- font-size: 14.5px;
- text-align: center;
- padding: calc(var(--padding) * 4) 0;
- }
-</style>
diff --git a/src/routes/courses/areademembros/+page.svelte b/src/routes/courses/areademembros/+page.svelte
deleted file mode 100644
index 355e436a..00000000
--- a/src/routes/courses/areademembros/+page.svelte
+++ /dev/null
@@ -1,616 +0,0 @@
-<script lang="ts">
- import { pluginInvoke } from "$lib/plugin-invoke";
- import { open } from "@tauri-apps/plugin-dialog";
- import CourseCard from "$components/hotmart/CourseCard.svelte";
- import { showToast } from "$lib/stores/toast-store.svelte";
- import { getDownloads } from "$lib/stores/download-store.svelte";
- import { getSettings } from "$lib/stores/settings-store.svelte";
- import { t } from "$lib/i18n";
-
- let downloads = $derived(getDownloads());
-
- type AreaDeMembrosApiCourse = {
- id: string;
- name: string;
- };
-
- let token = $state("");
- let siteUrl = $state("");
- let loading = $state(false);
- let error = $state("");
-
- let fileInput: HTMLInputElement = $state() as HTMLInputElement;
-
- function onFileSelected(e: Event) {
- const input = e.target as HTMLInputElement;
- const file = input.files?.[0];
- if (!file) return;
- const reader = new FileReader();
- reader.onload = () => { token = reader.result as string; };
- reader.readAsText(file);
- input.value = "";
- }
-
- let checking = $state(true);
- let loggedIn = $state(false);
- let sessionEmail = $state("");
-
- let courses: AreaDeMembrosApiCourse[] = $state([]);
- let loadingCourses = $state(false);
- let coursesError = $state("");
-
- const ITEMS_PER_PAGE = 12;
- let currentPage = $state(1);
-
- let totalPages = $derived(Math.max(1, Math.ceil(courses.length / ITEMS_PER_PAGE)));
- let paginatedCourses = $derived(
- courses.slice((currentPage - 1) * ITEMS_PER_PAGE, currentPage * ITEMS_PER_PAGE)
- );
-
- let pageNumbers = $derived((): number[] => {
- const pages: number[] = [];
- if (totalPages <= 7) {
- for (let i = 1; i <= totalPages; i++) pages.push(i);
- } else {
- pages.push(1);
- if (currentPage > 3) pages.push(-1);
- const start = Math.max(2, currentPage - 1);
- const end = Math.min(totalPages - 1, currentPage + 1);
- for (let i = start; i <= end; i++) pages.push(i);
- if (currentPage < totalPages - 2) pages.push(-1);
- pages.push(totalPages);
- }
- return pages;
- });
-
- function goToPage(page: number) {
- if (page >= 1 && page <= totalPages) {
- currentPage = page;
- }
- }
-
- $effect(() => {
- checkSession();
- });
-
- async function checkSession() {
- try {
- const result = await pluginInvoke<string>("courses", "areademembros_check_session");
- sessionEmail = result;
- loggedIn = true;
- loadCourses();
- } catch {
- loggedIn = false;
- } finally {
- checking = false;
- }
- }
-
- async function handleTokenLogin() {
- if (!token.trim()) return;
- error = "";
- loading = true;
- try {
- const result = await pluginInvoke<string>("courses", "areademembros_login_token", { token: token.trim(), siteUrl: siteUrl.trim() });
- sessionEmail = result || "Token";
- loggedIn = true;
- loadCourses();
- } catch (e: any) {
- error = typeof e === "string" ? e : e.message ?? $t('hotmart.unknown_error');
- } finally {
- loading = false;
- }
- }
-
- async function handleLogout() {
- try {
- await pluginInvoke("courses", "areademembros_logout");
- } catch {
- }
- loggedIn = false;
- sessionEmail = "";
- courses = [];
- coursesError = "";
- currentPage = 1;
- }
-
- async function loadCourses() {
- loadingCourses = true;
- coursesError = "";
- try {
- courses = await pluginInvoke("courses", "areademembros_list_courses");
- currentPage = 1;
- } catch (e: any) {
- coursesError = typeof e === "string" ? e : e.message ?? $t('hotmart.courses_error');
- } finally {
- loadingCourses = false;
- }
- }
-
- function getCourseDownloadStatus(courseId: string): "idle" | "downloading" | "complete" | "error" {
- const numId = Number(courseId) || 0;
- const item = downloads.get(numId);
- if (!item) return "idle";
- const s = item.status;
- if (s === "queued" || s === "paused" || s === "seeding") return "downloading";
- return s;
- }
-
- function getCourseDownloadPercent(courseId: string): number {
- const numId = Number(courseId) || 0;
- return downloads.get(numId)?.percent ?? 0;
- }
-
- async function downloadCourse(course: AreaDeMembrosApiCourse) {
- const status = getCourseDownloadStatus(course.id);
- if (status === "downloading") {
- showToast("info", $t("toast.download_already_active"));
- return;
- }
- if (status === "complete") return;
-
- const appSettings = getSettings();
- let outputDir: string | null = null;
-
- if (appSettings?.download.always_ask_path) {
- outputDir = await open({ directory: true, title: $t("hotmart.choose_folder") }) as string | null;
- if (!outputDir) return;
- } else {
- outputDir = appSettings?.download.default_output_dir ?? null;
- if (!outputDir) {
- outputDir = await open({ directory: true, title: $t("hotmart.choose_folder") }) as string | null;
- if (!outputDir) return;
- }
- }
-
- try {
- await pluginInvoke("courses", "start_areademembros_download", {
- courseJson: JSON.stringify(course),
- outputDir,
- });
- showToast("info", $t("toast.download_preparing"));
- } catch (e: any) {
- const msg = typeof e === "string" ? e : e.message ?? $t("common.error");
- showToast("error", msg);
- }
- }
-
- let refreshing = $state(false);
-
- async function refreshCourses() {
- refreshing = true;
- loadingCourses = true;
- coursesError = "";
- try {
- courses = await pluginInvoke("courses", "areademembros_refresh_courses");
- currentPage = 1;
- } catch (e: any) {
- coursesError = typeof e === "string" ? e : e.message ?? $t('hotmart.courses_error');
- } finally {
- loadingCourses = false;
- refreshing = false;
- }
- }
-</script>
-
-<a href="/courses" class="back-link">
- <svg viewBox="0 0 24 24" width="16" height="16" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
- <path d="M19 12H5" />
- <path d="M12 19l-7-7 7-7" />
- </svg>
- {$t("courses.back")}
-</a>
-
-{#if checking}
- <div class="page-center">
- <span class="spinner"></span>
- <span class="spinner-text">{$t('hotmart.checking_session')}</span>
- </div>
-{:else if loggedIn}
- <div class="page-logged">
- <div class="session-bar">
- <span class="session-info">
- {$t('hotmart.logged_as', { email: sessionEmail || "—" })}
- </span>
- <div class="session-actions">
- <button
- class="button"
- onclick={refreshCourses}
- disabled={refreshing}
- aria-label={$t('hotmart.refresh')}
- >
- <svg viewBox="0 0 24 24" width="14" height="14" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class:spinning={refreshing}>
- <path d="M21 2v6h-6" />
- <path d="M3 12a9 9 0 0115-6.7L21 8" />
- <path d="M3 22v-6h6" />
- <path d="M21 12a9 9 0 01-15 6.7L3 16" />
- </svg>
- </button>
- <button class="button" onclick={handleLogout}>{$t('hotmart.logout')}</button>
- </div>
- </div>
-
- {#if loadingCourses}
- <div class="spinner-section">
- <span class="spinner"></span>
- <span class="spinner-text">{$t('hotmart.loading_courses')}</span>
- </div>
- {:else if coursesError}
- <div class="error-section">
- <p class="error-msg">{coursesError}</p>
- <button class="button" onclick={loadCourses}>{$t('common.retry')}</button>
- </div>
- {:else if courses.length === 0}
- <p class="empty-text">{$t('hotmart.no_courses')}</p>
- {:else}
- <div class="courses-header">
- <h2>{$t('hotmart.courses_title')}</h2>
- <span class="subtext">{courses.length === 1 ? $t('hotmart.course_count_one', { count: courses.length }) : $t('hotmart.course_count', { count: courses.length })}</span>
- </div>
-
- <div class="courses-grid">
- {#each paginatedCourses as course (course.id)}
- <CourseCard
- name={course.name}
- price=""
- downloadStatus={getCourseDownloadStatus(course.id)}
- downloadPercent={getCourseDownloadPercent(course.id)}
- onDownload={() => downloadCourse(course)}
- />
- {/each}
- </div>
-
- {#if totalPages > 1}
- <div class="pagination">
- <span class="pagination-info">
- {$t('hotmart.page_of', { current: currentPage, total: totalPages })} &middot; {courses.length === 1 ? $t('hotmart.course_count_one', { count: courses.length }) : $t('hotmart.course_count', { count: courses.length })}
- </span>
- <div class="pagination-controls">
- <button
- class="button pagination-btn"
- disabled={currentPage <= 1}
- onclick={() => goToPage(currentPage - 1)}
- >
- &lt;
- </button>
-
- {#each pageNumbers() as page}
- {#if page === -1}
- <span class="pagination-ellipsis">&hellip;</span>
- {:else}
- <button
- class="button pagination-btn"
- class:active={page === currentPage}
- onclick={() => goToPage(page)}
- >
- {page}
- </button>
- {/if}
- {/each}
-
- <button
- class="button pagination-btn"
- disabled={currentPage >= totalPages}
- onclick={() => goToPage(currentPage + 1)}
- >
- &gt;
- </button>
- </div>
- </div>
- {/if}
- {/if}
- </div>
-{:else}
- <div class="page-center">
- <div class="login-card">
- <h2>Area de Membros</h2>
-
- <div class="form">
- <label class="field">
- <span class="field-label">Platform URL</span>
- <input
- type="url"
- placeholder="https://example.areademembros.com"
- bind:value={siteUrl}
- class="input"
- disabled={loading}
- />
- </label>
- <label class="field">
- <span class="field-label">Cookies JSON</span>
- <textarea
- class="input token-textarea"
- placeholder="Paste cookies JSON from browser extension or a raw token"
- bind:value={token}
- disabled={loading}
- rows="5"
- ></textarea>
- </label>
-
- <input
- type="file"
- accept=".json,.txt"
- class="hidden-file-input"
- bind:this={fileInput}
- onchange={onFileSelected}
- />
- <button class="button" onclick={() => fileInput?.click()} disabled={loading}>
- Import .json file
- </button>
-
- {#if error}
- <p class="error-msg">{error}</p>
- {/if}
-
- <button class="button" onclick={handleTokenLogin} disabled={loading || !token.trim()}>
- {#if loading}
- {$t('hotmart.authenticating')}
- {:else}
- {$t('hotmart.login')}
- {/if}
- </button>
- </div>
- </div>
- </div>
-{/if}
-
-<style>
- .back-link {
- display: inline-flex;
- align-items: center;
- gap: 6px;
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- margin-bottom: var(--padding);
- }
-
- @media (hover: hover) {
- .back-link:hover {
- color: var(--secondary);
- }
- }
-
- .page-center {
- display: flex;
- flex-direction: column;
- align-items: center;
- justify-content: center;
- min-height: calc(100vh - var(--padding) * 4 - 40px);
- gap: var(--padding);
- }
-
- .page-logged {
- display: flex;
- flex-direction: column;
- align-items: center;
- gap: calc(var(--padding) * 1.5);
- padding: calc(var(--padding) * 1.5);
- width: 100%;
- }
-
- .page-logged > :global(*) {
- width: 100%;
- max-width: 1200px;
- }
-
- .session-bar {
- display: flex;
- align-items: center;
- justify-content: space-between;
- }
-
- .session-info {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .session-actions {
- display: flex;
- gap: calc(var(--padding) / 2);
- }
-
- .session-bar :global(.button) {
- padding: calc(var(--padding) / 2) var(--padding);
- font-size: 12.5px;
- }
-
- .spinning {
- animation: spin 0.6s linear infinite;
- }
-
- .courses-header {
- display: flex;
- align-items: baseline;
- gap: var(--padding);
- }
-
- .courses-header h2 {
- margin-block: 0;
- }
-
- .subtext {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .courses-grid {
- display: grid;
- grid-template-columns: repeat(4, 1fr);
- gap: var(--padding);
- }
-
- @media (max-width: 1000px) {
- .courses-grid {
- grid-template-columns: repeat(3, 1fr);
- }
- }
-
- @media (max-width: 750px) {
- .courses-grid {
- grid-template-columns: repeat(2, 1fr);
- }
- }
-
- @media (max-width: 535px) {
- .courses-grid {
- grid-template-columns: 1fr;
- }
- }
-
- .pagination {
- display: flex;
- flex-direction: column;
- align-items: center;
- gap: var(--padding);
- padding-top: var(--padding);
- }
-
- .pagination-info {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .pagination-controls {
- display: flex;
- align-items: center;
- gap: calc(var(--padding) / 3);
- }
-
- .pagination-btn {
- min-width: 36px;
- height: 36px;
- padding: 0;
- display: flex;
- align-items: center;
- justify-content: center;
- font-size: 14.5px;
- }
-
- .pagination-ellipsis {
- min-width: 36px;
- text-align: center;
- color: var(--gray);
- font-size: 14.5px;
- }
-
- .login-card {
- width: 100%;
- max-width: 400px;
- background: var(--button-elevated);
- border-radius: var(--border-radius);
- padding: calc(var(--padding) * 2);
- display: flex;
- flex-direction: column;
- gap: calc(var(--padding) * 1.5);
- }
-
- .login-card h2 {
- margin-block: 0;
- }
-
- .hidden-file-input { display: none; }
-
- .token-textarea {
- resize: vertical;
- min-height: 80px;
- font-size: 11.5px;
- font-family: var(--font-mono);
- line-height: 1.5;
- }
-
- .form {
- display: flex;
- flex-direction: column;
- gap: var(--padding);
- }
-
- .field {
- display: flex;
- flex-direction: column;
- gap: calc(var(--padding) / 2);
- }
-
- .field-label {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .input {
- width: 100%;
- padding: var(--padding);
- font-size: 14.5px;
- background: var(--button);
- border-radius: var(--border-radius);
- color: var(--secondary);
- border: 1px solid var(--input-border);
- }
-
- .input::placeholder {
- color: var(--gray);
- }
-
- .input:focus-visible {
- border-color: var(--secondary);
- outline: none;
- }
-
- .input:disabled {
- opacity: 0.5;
- cursor: default;
- }
-
- .error-msg {
- color: var(--red);
- font-size: 12.5px;
- font-weight: 500;
- }
-
- .spinner-section {
- display: flex;
- flex-direction: column;
- align-items: center;
- gap: var(--padding);
- padding: calc(var(--padding) * 4) 0;
- }
-
- .spinner {
- width: 24px;
- height: 24px;
- border: 2px solid var(--input-border);
- border-top-color: var(--blue);
- border-radius: 50%;
- animation: spin 0.6s linear infinite;
- }
-
- @keyframes spin {
- to {
- transform: rotate(360deg);
- }
- }
-
- .spinner-text {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .error-section {
- display: flex;
- flex-direction: column;
- align-items: center;
- gap: var(--padding);
- padding: calc(var(--padding) * 2) 0;
- }
-
- .empty-text {
- color: var(--gray);
- font-size: 14.5px;
- text-align: center;
- padding: calc(var(--padding) * 4) 0;
- }
-</style>
diff --git a/src/routes/courses/astronmembers/+page.svelte b/src/routes/courses/astronmembers/+page.svelte
deleted file mode 100644
index 0b3219ae..00000000
--- a/src/routes/courses/astronmembers/+page.svelte
+++ /dev/null
@@ -1,713 +0,0 @@
-<script lang="ts">
- import { pluginInvoke } from "$lib/plugin-invoke";
- import { open } from "@tauri-apps/plugin-dialog";
- import CourseCard from "$components/hotmart/CourseCard.svelte";
- import { showToast } from "$lib/stores/toast-store.svelte";
- import { getDownloads } from "$lib/stores/download-store.svelte";
- import { getSettings } from "$lib/stores/settings-store.svelte";
- import { t } from "$lib/i18n";
-
- let downloads = $derived(getDownloads());
-
- type AstronCourse = {
- id: string;
- name: string;
- slug: string;
- };
-
- let email = $state("");
- let password = $state("");
- let token = $state("");
- let fileInput: HTMLInputElement = $state() as HTMLInputElement;
- function onFileSelected(e: Event) {
- const input = e.target as HTMLInputElement;
- const file = input.files?.[0];
- if (!file) return;
- const reader = new FileReader();
- reader.onload = () => { token = reader.result as string; };
- reader.readAsText(file);
- input.value = "";
- }
- let siteUrl = $state("");
- let loading = $state(false);
- let error = $state("");
-
- let checking = $state(true);
- let loggedIn = $state(false);
- let sessionEmail = $state("");
-
- let loginMode = $state<"credentials" | "token">("credentials");
-
- let courses: AstronCourse[] = $state([]);
- let loadingCourses = $state(false);
- let coursesError = $state("");
-
- const ITEMS_PER_PAGE = 12;
- let currentPage = $state(1);
-
- let totalPages = $derived(Math.max(1, Math.ceil(courses.length / ITEMS_PER_PAGE)));
- let paginatedCourses = $derived(
- courses.slice((currentPage - 1) * ITEMS_PER_PAGE, currentPage * ITEMS_PER_PAGE)
- );
-
- let pageNumbers = $derived((): number[] => {
- const pages: number[] = [];
- if (totalPages <= 7) {
- for (let i = 1; i <= totalPages; i++) pages.push(i);
- } else {
- pages.push(1);
- if (currentPage > 3) pages.push(-1);
- const start = Math.max(2, currentPage - 1);
- const end = Math.min(totalPages - 1, currentPage + 1);
- for (let i = start; i <= end; i++) pages.push(i);
- if (currentPage < totalPages - 2) pages.push(-1);
- pages.push(totalPages);
- }
- return pages;
- });
-
- function goToPage(page: number) {
- if (page >= 1 && page <= totalPages) {
- currentPage = page;
- }
- }
-
- $effect(() => {
- checkSession();
- });
-
- async function checkSession() {
- try {
- const result = await pluginInvoke<string>("courses", "astronmembers_check_session");
- sessionEmail = result;
- loggedIn = true;
- loadCourses();
- } catch {
- loggedIn = false;
- } finally {
- checking = false;
- }
- }
-
- async function handleLogin() {
- error = "";
- loading = true;
- try {
- const result = await pluginInvoke<string>("courses", "astronmembers_login", { email, password, siteUrl });
- sessionEmail = result || email;
- loggedIn = true;
- loadCourses();
- } catch (e: any) {
- error = typeof e === "string" ? e : e.message ?? $t('hotmart.unknown_error');
- } finally {
- loading = false;
- }
- }
-
- async function handleTokenLogin() {
- if (!token.trim()) return;
- error = "";
- loading = true;
- try {
- const result = await pluginInvoke<string>("courses", "astronmembers_login_token", { token: token.trim(), siteUrl });
- sessionEmail = result || "Token";
- loggedIn = true;
- loadCourses();
- } catch (e: any) {
- error = typeof e === "string" ? e : e.message ?? $t('hotmart.unknown_error');
- } finally {
- loading = false;
- }
- }
-
- async function handleLogout() {
- try {
- await pluginInvoke("courses", "astronmembers_logout");
- } catch {
- }
- loggedIn = false;
- sessionEmail = "";
- courses = [];
- coursesError = "";
- currentPage = 1;
- }
-
- async function loadCourses() {
- loadingCourses = true;
- coursesError = "";
- try {
- courses = await pluginInvoke("courses", "astronmembers_list_courses");
- currentPage = 1;
- } catch (e: any) {
- coursesError = typeof e === "string" ? e : e.message ?? $t('hotmart.courses_error');
- } finally {
- loadingCourses = false;
- }
- }
-
- function getCourseDownloadStatus(courseId: string): "idle" | "downloading" | "complete" | "error" {
- const numId = Number(courseId) || 0;
- const item = downloads.get(numId);
- if (!item) return "idle";
- const s = item.status;
- if (s === "queued" || s === "paused" || s === "seeding") return "downloading";
- return s;
- }
-
- function getCourseDownloadPercent(courseId: string): number {
- const numId = Number(courseId) || 0;
- return downloads.get(numId)?.percent ?? 0;
- }
-
- async function downloadCourse(course: AstronCourse) {
- const status = getCourseDownloadStatus(course.id);
- if (status === "downloading") {
- showToast("info", $t("toast.download_already_active"));
- return;
- }
- if (status === "complete") return;
-
- const appSettings = getSettings();
- let outputDir: string | null = null;
-
- if (appSettings?.download.always_ask_path) {
- outputDir = await open({ directory: true, title: $t("hotmart.choose_folder") }) as string | null;
- if (!outputDir) return;
- } else {
- outputDir = appSettings?.download.default_output_dir ?? null;
- if (!outputDir) {
- outputDir = await open({ directory: true, title: $t("hotmart.choose_folder") }) as string | null;
- if (!outputDir) return;
- }
- }
-
- try {
- await pluginInvoke("courses", "start_astronmembers_download", {
- courseJson: JSON.stringify(course),
- outputDir,
- });
- showToast("info", $t("toast.download_preparing"));
- } catch (e: any) {
- const msg = typeof e === "string" ? e : e.message ?? $t("common.error");
- showToast("error", msg);
- }
- }
-
- let refreshing = $state(false);
-
- async function refreshCourses() {
- refreshing = true;
- loadingCourses = true;
- coursesError = "";
- try {
- courses = await pluginInvoke("courses", "astronmembers_refresh_courses");
- currentPage = 1;
- } catch (e: any) {
- coursesError = typeof e === "string" ? e : e.message ?? $t('hotmart.courses_error');
- } finally {
- loadingCourses = false;
- refreshing = false;
- }
- }
-</script>
-
-<a href="/courses" class="back-link">
- <svg viewBox="0 0 24 24" width="16" height="16" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
- <path d="M19 12H5" />
- <path d="M12 19l-7-7 7-7" />
- </svg>
- {$t("courses.back")}
-</a>
-
-{#if checking}
- <div class="page-center">
- <span class="spinner"></span>
- <span class="spinner-text">{$t('hotmart.checking_session')}</span>
- </div>
-{:else if loggedIn}
- <div class="page-logged">
- <div class="session-bar">
- <span class="session-info">
- {$t('hotmart.logged_as', { email: sessionEmail || "—" })}
- </span>
- <div class="session-actions">
- <button
- class="button"
- onclick={refreshCourses}
- disabled={refreshing}
- aria-label={$t('hotmart.refresh')}
- >
- <svg viewBox="0 0 24 24" width="14" height="14" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class:spinning={refreshing}>
- <path d="M21 2v6h-6" />
- <path d="M3 12a9 9 0 0115-6.7L21 8" />
- <path d="M3 22v-6h6" />
- <path d="M21 12a9 9 0 01-15 6.7L3 16" />
- </svg>
- </button>
- <button class="button" onclick={handleLogout}>{$t('hotmart.logout')}</button>
- </div>
- </div>
-
- {#if loadingCourses}
- <div class="spinner-section">
- <span class="spinner"></span>
- <span class="spinner-text">{$t('hotmart.loading_courses')}</span>
- </div>
- {:else if coursesError}
- <div class="error-section">
- <p class="error-msg">{coursesError}</p>
- <button class="button" onclick={loadCourses}>{$t('common.retry')}</button>
- </div>
- {:else if courses.length === 0}
- <p class="empty-text">{$t('hotmart.no_courses')}</p>
- {:else}
- <div class="courses-header">
- <h2>{$t('hotmart.courses_title')}</h2>
- <span class="subtext">{courses.length === 1 ? $t('hotmart.course_count_one', { count: courses.length }) : $t('hotmart.course_count', { count: courses.length })}</span>
- </div>
-
- <div class="courses-grid">
- {#each paginatedCourses as course (course.id)}
- <CourseCard
- name={course.name}
- price=""
- downloadStatus={getCourseDownloadStatus(course.id)}
- downloadPercent={getCourseDownloadPercent(course.id)}
- onDownload={() => downloadCourse(course)}
- />
- {/each}
- </div>
-
- {#if totalPages > 1}
- <div class="pagination">
- <span class="pagination-info">
- {$t('hotmart.page_of', { current: currentPage, total: totalPages })} &middot; {courses.length === 1 ? $t('hotmart.course_count_one', { count: courses.length }) : $t('hotmart.course_count', { count: courses.length })}
- </span>
- <div class="pagination-controls">
- <button
- class="button pagination-btn"
- disabled={currentPage <= 1}
- onclick={() => goToPage(currentPage - 1)}
- >
- &lt;
- </button>
-
- {#each pageNumbers() as page}
- {#if page === -1}
- <span class="pagination-ellipsis">&hellip;</span>
- {:else}
- <button
- class="button pagination-btn"
- class:active={page === currentPage}
- onclick={() => goToPage(page)}
- >
- {page}
- </button>
- {/if}
- {/each}
-
- <button
- class="button pagination-btn"
- disabled={currentPage >= totalPages}
- onclick={() => goToPage(currentPage + 1)}
- >
- &gt;
- </button>
- </div>
- </div>
- {/if}
- {/if}
- </div>
-{:else}
- <div class="page-center">
- <div class="login-card">
- <h2>Astron Members</h2>
-
- <div class="login-tabs">
- <button
- class="button login-tab"
- class:active={loginMode === "credentials"}
- onclick={() => { loginMode = "credentials"; error = ""; }}
- >
- Login
- </button>
- <button
- class="button login-tab"
- class:active={loginMode === "token"}
- onclick={() => { loginMode = "token"; error = ""; }}
- >
- Cookie
- </button>
- </div>
-
- {#if loginMode === "credentials"}
- <form class="form" onsubmit={(e) => { e.preventDefault(); handleLogin(); }}>
- <label class="field">
- <span class="field-label">{$t('hotmart.email_label')}</span>
- <input
- type="email"
- placeholder={$t('hotmart.email_placeholder')}
- bind:value={email}
- class="input"
- disabled={loading}
- required
- />
- </label>
- <label class="field">
- <span class="field-label">{$t('hotmart.password_label')}</span>
- <input
- type="password"
- placeholder={$t('hotmart.password_placeholder')}
- bind:value={password}
- class="input"
- disabled={loading}
- required
- />
- </label>
- <label class="field">
- <span class="field-label">Site URL</span>
- <input
- type="url"
- placeholder="https://your-site.astronmembers.com"
- bind:value={siteUrl}
- class="input"
- disabled={loading}
- />
- </label>
-
- {#if error}
- <p class="error-msg">{error}</p>
- {/if}
-
- <button type="submit" class="button" disabled={loading}>
- {#if loading}
- {$t('hotmart.authenticating')}
- {:else}
- {$t('hotmart.login')}
- {/if}
- </button>
- </form>
- {:else}
- <div class="form">
- <label class="field">
- <span class="field-label">Cookies JSON</span>
- <textarea
- class="input token-textarea"
- placeholder="Paste cookies JSON from browser extension or a raw token"
- bind:value={token}
- disabled={loading}
- rows="4"
- ></textarea>
- </label>
- <input type="file" accept=".json,.txt" class="hidden-file-input" bind:this={fileInput} onchange={onFileSelected} />
- <button class="button" onclick={() => fileInput?.click()} disabled={loading}>Import .json file</button>
- <label class="field">
- <span class="field-label">Site URL</span>
- <input
- type="url"
- placeholder="https://your-site.astronmembers.com"
- bind:value={siteUrl}
- class="input"
- disabled={loading}
- />
- </label>
-
- {#if error}
- <p class="error-msg">{error}</p>
- {/if}
-
- <button class="button" onclick={handleTokenLogin} disabled={loading || !token.trim()}>
- {#if loading}
- {$t('hotmart.authenticating')}
- {:else}
- {$t('hotmart.login')}
- {/if}
- </button>
- </div>
- {/if}
- </div>
- </div>
-{/if}
-
-<style>
- .back-link {
- display: inline-flex;
- align-items: center;
- gap: 6px;
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- margin-bottom: var(--padding);
- }
-
- @media (hover: hover) {
- .back-link:hover {
- color: var(--secondary);
- }
- }
-
- .page-center {
- display: flex;
- flex-direction: column;
- align-items: center;
- justify-content: center;
- min-height: calc(100vh - var(--padding) * 4 - 40px);
- gap: var(--padding);
- }
-
- .page-logged {
- display: flex;
- flex-direction: column;
- align-items: center;
- gap: calc(var(--padding) * 1.5);
- padding: calc(var(--padding) * 1.5);
- width: 100%;
- }
-
- .page-logged > :global(*) {
- width: 100%;
- max-width: 1200px;
- }
-
- .session-bar {
- display: flex;
- align-items: center;
- justify-content: space-between;
- }
-
- .session-info {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .session-actions {
- display: flex;
- gap: calc(var(--padding) / 2);
- }
-
- .session-bar :global(.button) {
- padding: calc(var(--padding) / 2) var(--padding);
- font-size: 12.5px;
- }
-
- .spinning {
- animation: spin 0.6s linear infinite;
- }
-
- .courses-header {
- display: flex;
- align-items: baseline;
- gap: var(--padding);
- }
-
- .courses-header h2 {
- margin-block: 0;
- }
-
- .subtext {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .courses-grid {
- display: grid;
- grid-template-columns: repeat(4, 1fr);
- gap: var(--padding);
- }
-
- @media (max-width: 1000px) {
- .courses-grid {
- grid-template-columns: repeat(3, 1fr);
- }
- }
-
- @media (max-width: 750px) {
- .courses-grid {
- grid-template-columns: repeat(2, 1fr);
- }
- }
-
- @media (max-width: 535px) {
- .courses-grid {
- grid-template-columns: 1fr;
- }
- }
-
- .pagination {
- display: flex;
- flex-direction: column;
- align-items: center;
- gap: var(--padding);
- padding-top: var(--padding);
- }
-
- .pagination-info {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .pagination-controls {
- display: flex;
- align-items: center;
- gap: calc(var(--padding) / 3);
- }
-
- .pagination-btn {
- min-width: 36px;
- height: 36px;
- padding: 0;
- display: flex;
- align-items: center;
- justify-content: center;
- font-size: 14.5px;
- }
-
- .pagination-ellipsis {
- min-width: 36px;
- text-align: center;
- color: var(--gray);
- font-size: 14.5px;
- }
-
- .login-card {
- width: 100%;
- max-width: 400px;
- background: var(--button-elevated);
- border-radius: var(--border-radius);
- padding: calc(var(--padding) * 2);
- display: flex;
- flex-direction: column;
- gap: calc(var(--padding) * 1.5);
- }
-
- .login-card h2 {
- margin-block: 0;
- }
-
- .login-tabs {
- display: flex;
- gap: 0;
- }
-
- .login-tab {
- flex: 1;
- border-radius: 0;
- font-size: 12.5px;
- padding: calc(var(--padding) * 0.75) var(--padding);
- }
-
- .login-tab:first-child {
- border-radius: var(--border-radius) 0 0 var(--border-radius);
- }
-
- .login-tab:last-child {
- border-radius: 0 var(--border-radius) var(--border-radius) 0;
- }
-
- .hidden-file-input {
- display: none;
- }
-
- .token-textarea {
- resize: vertical;
- min-height: 80px;
- font-size: 11.5px;
- font-family: var(--font-mono);
- line-height: 1.5;
- }
-
- .form {
- display: flex;
- flex-direction: column;
- gap: var(--padding);
- }
-
- .field {
- display: flex;
- flex-direction: column;
- gap: calc(var(--padding) / 2);
- }
-
- .field-label {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .input {
- width: 100%;
- padding: var(--padding);
- font-size: 14.5px;
- background: var(--button);
- border-radius: var(--border-radius);
- color: var(--secondary);
- border: 1px solid var(--input-border);
- }
-
- .input::placeholder {
- color: var(--gray);
- }
-
- .input:focus-visible {
- border-color: var(--secondary);
- outline: none;
- }
-
- .input:disabled {
- opacity: 0.5;
- cursor: default;
- }
-
- .error-msg {
- color: var(--red);
- font-size: 12.5px;
- font-weight: 500;
- }
-
- .spinner-section {
- display: flex;
- flex-direction: column;
- align-items: center;
- gap: var(--padding);
- padding: calc(var(--padding) * 4) 0;
- }
-
- .spinner {
- width: 24px;
- height: 24px;
- border: 2px solid var(--input-border);
- border-top-color: var(--blue);
- border-radius: 50%;
- animation: spin 0.6s linear infinite;
- }
-
- @keyframes spin {
- to {
- transform: rotate(360deg);
- }
- }
-
- .spinner-text {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .error-section {
- display: flex;
- flex-direction: column;
- align-items: center;
- gap: var(--padding);
- padding: calc(var(--padding) * 2) 0;
- }
-
- .empty-text {
- color: var(--gray);
- font-size: 14.5px;
- text-align: center;
- padding: calc(var(--padding) * 4) 0;
- }
-</style>
\ No newline at end of file
diff --git a/src/routes/courses/cademi/+page.svelte b/src/routes/courses/cademi/+page.svelte
deleted file mode 100644
index 99afd7dd..00000000
--- a/src/routes/courses/cademi/+page.svelte
+++ /dev/null
@@ -1,722 +0,0 @@
-<script lang="ts">
- import { pluginInvoke } from "$lib/plugin-invoke";
- import { open } from "@tauri-apps/plugin-dialog";
- import CourseCard from "$components/hotmart/CourseCard.svelte";
- import { showToast } from "$lib/stores/toast-store.svelte";
- import { getDownloads } from "$lib/stores/download-store.svelte";
- import { getSettings } from "$lib/stores/settings-store.svelte";
- import { t } from "$lib/i18n";
-
- let downloads = $derived(getDownloads());
-
- type CademiCourse = {
- id: string;
- name: string;
- };
-
- let email = $state("");
- let password = $state("");
- let cookie = $state("");
- let siteUrl = $state("");
- let loading = $state(false);
- let error = $state("");
-
- let checking = $state(true);
- let loggedIn = $state(false);
- let sessionEmail = $state("");
-
- let loginMode = $state<"credentials" | "cookie">("credentials");
-
- let fileInput: HTMLInputElement = $state() as HTMLInputElement;
-
- function onFileSelected(e: Event) {
- const input = e.target as HTMLInputElement;
- const file = input.files?.[0];
- if (!file) return;
- const reader = new FileReader();
- reader.onload = () => { cookie = reader.result as string; };
- reader.readAsText(file);
- input.value = "";
- }
-
- let courses: CademiCourse[] = $state([]);
- let loadingCourses = $state(false);
- let coursesError = $state("");
-
- const ITEMS_PER_PAGE = 12;
- let currentPage = $state(1);
-
- let totalPages = $derived(Math.max(1, Math.ceil(courses.length / ITEMS_PER_PAGE)));
- let paginatedCourses = $derived(
- courses.slice((currentPage - 1) * ITEMS_PER_PAGE, currentPage * ITEMS_PER_PAGE)
- );
-
- let pageNumbers = $derived((): number[] => {
- const pages: number[] = [];
- if (totalPages <= 7) {
- for (let i = 1; i <= totalPages; i++) pages.push(i);
- } else {
- pages.push(1);
- if (currentPage > 3) pages.push(-1);
- const start = Math.max(2, currentPage - 1);
- const end = Math.min(totalPages - 1, currentPage + 1);
- for (let i = start; i <= end; i++) pages.push(i);
- if (currentPage < totalPages - 2) pages.push(-1);
- pages.push(totalPages);
- }
- return pages;
- });
-
- function goToPage(page: number) {
- if (page >= 1 && page <= totalPages) {
- currentPage = page;
- }
- }
-
- $effect(() => {
- checkSession();
- });
-
- async function checkSession() {
- try {
- const result = await pluginInvoke<string>("courses", "cademi_check_session");
- sessionEmail = result;
- loggedIn = true;
- loadCourses();
- } catch {
- loggedIn = false;
- } finally {
- checking = false;
- }
- }
-
- async function handleLogin() {
- error = "";
- loading = true;
- try {
- const result = await pluginInvoke<string>("courses", "cademi_login", { email, password, siteUrl: siteUrl.trim() });
- sessionEmail = result || email;
- loggedIn = true;
- loadCourses();
- } catch (e: any) {
- error = typeof e === "string" ? e : e.message ?? $t('hotmart.unknown_error');
- } finally {
- loading = false;
- }
- }
-
- async function handleCookieLogin() {
- if (!cookie.trim()) return;
- error = "";
- loading = true;
- try {
- const result = await pluginInvoke<string>("courses", "cademi_login_cookie", { cookie: cookie.trim(), siteUrl: siteUrl.trim() });
- sessionEmail = result || "Cookie";
- loggedIn = true;
- loadCourses();
- } catch (e: any) {
- error = typeof e === "string" ? e : e.message ?? $t('hotmart.unknown_error');
- } finally {
- loading = false;
- }
- }
-
- async function handleLogout() {
- try {
- await pluginInvoke("courses", "cademi_logout");
- } catch {
- }
- loggedIn = false;
- sessionEmail = "";
- courses = [];
- coursesError = "";
- currentPage = 1;
- }
-
- async function loadCourses() {
- loadingCourses = true;
- coursesError = "";
- try {
- courses = await pluginInvoke("courses", "cademi_list_courses");
- currentPage = 1;
- } catch (e: any) {
- coursesError = typeof e === "string" ? e : e.message ?? $t('hotmart.courses_error');
- } finally {
- loadingCourses = false;
- }
- }
-
- function getCourseDownloadStatus(courseId: string): "idle" | "downloading" | "complete" | "error" {
- const numId = Number(courseId) || 0;
- const item = downloads.get(numId);
- if (!item) return "idle";
- const s = item.status;
- if (s === "queued" || s === "paused" || s === "seeding") return "downloading";
- return s;
- }
-
- function getCourseDownloadPercent(courseId: string): number {
- const numId = Number(courseId) || 0;
- return downloads.get(numId)?.percent ?? 0;
- }
-
- async function downloadCourse(course: CademiCourse) {
- const status = getCourseDownloadStatus(course.id);
- if (status === "downloading") {
- showToast("info", $t("toast.download_already_active"));
- return;
- }
- if (status === "complete") return;
-
- const appSettings = getSettings();
- let outputDir: string | null = null;
-
- if (appSettings?.download.always_ask_path) {
- outputDir = await open({ directory: true, title: $t("hotmart.choose_folder") }) as string | null;
- if (!outputDir) return;
- } else {
- outputDir = appSettings?.download.default_output_dir ?? null;
- if (!outputDir) {
- outputDir = await open({ directory: true, title: $t("hotmart.choose_folder") }) as string | null;
- if (!outputDir) return;
- }
- }
-
- try {
- await pluginInvoke("courses", "start_cademi_download", {
- courseJson: JSON.stringify(course),
- outputDir,
- });
- showToast("info", $t("toast.download_preparing"));
- } catch (e: any) {
- const msg = typeof e === "string" ? e : e.message ?? $t("common.error");
- showToast("error", msg);
- }
- }
-
- let refreshing = $state(false);
-
- async function refreshCourses() {
- refreshing = true;
- loadingCourses = true;
- coursesError = "";
- try {
- courses = await pluginInvoke("courses", "cademi_refresh_courses");
- currentPage = 1;
- } catch (e: any) {
- coursesError = typeof e === "string" ? e : e.message ?? $t('hotmart.courses_error');
- } finally {
- loadingCourses = false;
- refreshing = false;
- }
- }
-</script>
-
-<a href="/courses" class="back-link">
- <svg viewBox="0 0 24 24" width="16" height="16" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
- <path d="M19 12H5" />
- <path d="M12 19l-7-7 7-7" />
- </svg>
- {$t("courses.back")}
-</a>
-
-{#if checking}
- <div class="page-center">
- <span class="spinner"></span>
- <span class="spinner-text">{$t('hotmart.checking_session')}</span>
- </div>
-{:else if loggedIn}
- <div class="page-logged">
- <div class="session-bar">
- <span class="session-info">
- {$t('hotmart.logged_as', { email: sessionEmail || "—" })}
- </span>
- <div class="session-actions">
- <button
- class="button"
- onclick={refreshCourses}
- disabled={refreshing}
- aria-label={$t('hotmart.refresh')}
- >
- <svg viewBox="0 0 24 24" width="14" height="14" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class:spinning={refreshing}>
- <path d="M21 2v6h-6" />
- <path d="M3 12a9 9 0 0115-6.7L21 8" />
- <path d="M3 22v-6h6" />
- <path d="M21 12a9 9 0 01-15 6.7L3 16" />
- </svg>
- </button>
- <button class="button" onclick={handleLogout}>{$t('hotmart.logout')}</button>
- </div>
- </div>
-
- {#if loadingCourses}
- <div class="spinner-section">
- <span class="spinner"></span>
- <span class="spinner-text">{$t('hotmart.loading_courses')}</span>
- </div>
- {:else if coursesError}
- <div class="error-section">
- <p class="error-msg">{coursesError}</p>
- <button class="button" onclick={loadCourses}>{$t('common.retry')}</button>
- </div>
- {:else if courses.length === 0}
- <p class="empty-text">{$t('hotmart.no_courses')}</p>
- {:else}
- <div class="courses-header">
- <h2>{$t('hotmart.courses_title')}</h2>
- <span class="subtext">{courses.length === 1 ? $t('hotmart.course_count_one', { count: courses.length }) : $t('hotmart.course_count', { count: courses.length })}</span>
- </div>
-
- <div class="courses-grid">
- {#each paginatedCourses as course (course.id)}
- <CourseCard
- name={course.name}
- price=""
- downloadStatus={getCourseDownloadStatus(course.id)}
- downloadPercent={getCourseDownloadPercent(course.id)}
- onDownload={() => downloadCourse(course)}
- />
- {/each}
- </div>
-
- {#if totalPages > 1}
- <div class="pagination">
- <span class="pagination-info">
- {$t('hotmart.page_of', { current: currentPage, total: totalPages })} &middot; {courses.length === 1 ? $t('hotmart.course_count_one', { count: courses.length }) : $t('hotmart.course_count', { count: courses.length })}
- </span>
- <div class="pagination-controls">
- <button
- class="button pagination-btn"
- disabled={currentPage <= 1}
- onclick={() => goToPage(currentPage - 1)}
- >
- &lt;
- </button>
-
- {#each pageNumbers() as page}
- {#if page === -1}
- <span class="pagination-ellipsis">&hellip;</span>
- {:else}
- <button
- class="button pagination-btn"
- class:active={page === currentPage}
- onclick={() => goToPage(page)}
- >
- {page}
- </button>
- {/if}
- {/each}
-
- <button
- class="button pagination-btn"
- disabled={currentPage >= totalPages}
- onclick={() => goToPage(currentPage + 1)}
- >
- &gt;
- </button>
- </div>
- </div>
- {/if}
- {/if}
- </div>
-{:else}
- <div class="page-center">
- <div class="login-card">
- <h2>Cademi</h2>
-
- <div class="login-tabs">
- <button
- class="button login-tab"
- class:active={loginMode === "credentials"}
- onclick={() => { loginMode = "credentials"; error = ""; }}
- >
- Email & Password
- </button>
- <button
- class="button login-tab"
- class:active={loginMode === "cookie"}
- onclick={() => { loginMode = "cookie"; error = ""; }}
- >
- Cookie
- </button>
- </div>
-
- {#if loginMode === "credentials"}
- <form class="form" onsubmit={(e) => { e.preventDefault(); handleLogin(); }}>
- <label class="field">
- <span class="field-label">Platform URL</span>
- <input
- type="url"
- placeholder="https://example.cademi.com.br"
- bind:value={siteUrl}
- class="input"
- disabled={loading}
- required
- />
- </label>
- <label class="field">
- <span class="field-label">{$t('hotmart.email_label')}</span>
- <input
- type="email"
- placeholder={$t('hotmart.email_placeholder')}
- bind:value={email}
- class="input"
- disabled={loading}
- required
- />
- </label>
- <label class="field">
- <span class="field-label">{$t('hotmart.password_label')}</span>
- <input
- type="password"
- placeholder={$t('hotmart.password_placeholder')}
- bind:value={password}
- class="input"
- disabled={loading}
- required
- />
- </label>
-
- {#if error}
- <p class="error-msg">{error}</p>
- {/if}
-
- <button type="submit" class="button" disabled={loading}>
- {#if loading}
- {$t('hotmart.authenticating')}
- {:else}
- {$t('hotmart.login')}
- {/if}
- </button>
- </form>
- {:else}
- <div class="form">
- <label class="field">
- <span class="field-label">Platform URL</span>
- <input
- type="url"
- placeholder="https://example.cademi.com.br"
- bind:value={siteUrl}
- class="input"
- disabled={loading}
- />
- </label>
- <label class="field">
- <span class="field-label">Cookies JSON</span>
- <textarea
- class="input token-textarea"
- placeholder="Paste cookies JSON from browser extension or a raw token"
- bind:value={cookie}
- disabled={loading}
- rows="5"
- ></textarea>
- </label>
-
- <input
- type="file"
- accept=".json,.txt"
- class="hidden-file-input"
- bind:this={fileInput}
- onchange={onFileSelected}
- />
- <button class="button" onclick={() => fileInput?.click()} disabled={loading}>
- Import .json file
- </button>
-
- {#if error}
- <p class="error-msg">{error}</p>
- {/if}
-
- <button class="button" onclick={handleCookieLogin} disabled={loading || !cookie.trim()}>
- {#if loading}
- {$t('hotmart.authenticating')}
- {:else}
- {$t('hotmart.login')}
- {/if}
- </button>
- </div>
- {/if}
- </div>
- </div>
-{/if}
-
-<style>
- .back-link {
- display: inline-flex;
- align-items: center;
- gap: 6px;
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- margin-bottom: var(--padding);
- }
-
- @media (hover: hover) {
- .back-link:hover {
- color: var(--secondary);
- }
- }
-
- .page-center {
- display: flex;
- flex-direction: column;
- align-items: center;
- justify-content: center;
- min-height: calc(100vh - var(--padding) * 4 - 40px);
- gap: var(--padding);
- }
-
- .page-logged {
- display: flex;
- flex-direction: column;
- align-items: center;
- gap: calc(var(--padding) * 1.5);
- padding: calc(var(--padding) * 1.5);
- width: 100%;
- }
-
- .page-logged > :global(*) {
- width: 100%;
- max-width: 1200px;
- }
-
- .session-bar {
- display: flex;
- align-items: center;
- justify-content: space-between;
- }
-
- .session-info {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .session-actions {
- display: flex;
- gap: calc(var(--padding) / 2);
- }
-
- .session-bar :global(.button) {
- padding: calc(var(--padding) / 2) var(--padding);
- font-size: 12.5px;
- }
-
- .spinning {
- animation: spin 0.6s linear infinite;
- }
-
- .courses-header {
- display: flex;
- align-items: baseline;
- gap: var(--padding);
- }
-
- .courses-header h2 {
- margin-block: 0;
- }
-
- .subtext {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .courses-grid {
- display: grid;
- grid-template-columns: repeat(4, 1fr);
- gap: var(--padding);
- }
-
- @media (max-width: 1000px) {
- .courses-grid {
- grid-template-columns: repeat(3, 1fr);
- }
- }
-
- @media (max-width: 750px) {
- .courses-grid {
- grid-template-columns: repeat(2, 1fr);
- }
- }
-
- @media (max-width: 535px) {
- .courses-grid {
- grid-template-columns: 1fr;
- }
- }
-
- .pagination {
- display: flex;
- flex-direction: column;
- align-items: center;
- gap: var(--padding);
- padding-top: var(--padding);
- }
-
- .pagination-info {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .pagination-controls {
- display: flex;
- align-items: center;
- gap: calc(var(--padding) / 3);
- }
-
- .pagination-btn {
- min-width: 36px;
- height: 36px;
- padding: 0;
- display: flex;
- align-items: center;
- justify-content: center;
- font-size: 14.5px;
- }
-
- .pagination-ellipsis {
- min-width: 36px;
- text-align: center;
- color: var(--gray);
- font-size: 14.5px;
- }
-
- .login-card {
- width: 100%;
- max-width: 400px;
- background: var(--button-elevated);
- border-radius: var(--border-radius);
- padding: calc(var(--padding) * 2);
- display: flex;
- flex-direction: column;
- gap: calc(var(--padding) * 1.5);
- }
-
- .login-card h2 {
- margin-block: 0;
- }
-
- .login-tabs {
- display: flex;
- gap: 0;
- }
-
- .login-tab {
- flex: 1;
- border-radius: 0;
- font-size: 12.5px;
- padding: calc(var(--padding) * 0.75) var(--padding);
- }
-
- .login-tab:first-child {
- border-radius: var(--border-radius) 0 0 var(--border-radius);
- }
-
- .login-tab:last-child {
- border-radius: 0 var(--border-radius) var(--border-radius) 0;
- }
-
- .hidden-file-input { display: none; }
-
- .token-textarea {
- resize: vertical;
- min-height: 80px;
- font-size: 11.5px;
- font-family: var(--font-mono);
- line-height: 1.5;
- }
-
- .form {
- display: flex;
- flex-direction: column;
- gap: var(--padding);
- }
-
- .field {
- display: flex;
- flex-direction: column;
- gap: calc(var(--padding) / 2);
- }
-
- .field-label {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .input {
- width: 100%;
- padding: var(--padding);
- font-size: 14.5px;
- background: var(--button);
- border-radius: var(--border-radius);
- color: var(--secondary);
- border: 1px solid var(--input-border);
- }
-
- .input::placeholder {
- color: var(--gray);
- }
-
- .input:focus-visible {
- border-color: var(--secondary);
- outline: none;
- }
-
- .input:disabled {
- opacity: 0.5;
- cursor: default;
- }
-
- .error-msg {
- color: var(--red);
- font-size: 12.5px;
- font-weight: 500;
- }
-
- .spinner-section {
- display: flex;
- flex-direction: column;
- align-items: center;
- gap: var(--padding);
- padding: calc(var(--padding) * 4) 0;
- }
-
- .spinner {
- width: 24px;
- height: 24px;
- border: 2px solid var(--input-border);
- border-top-color: var(--blue);
- border-radius: 50%;
- animation: spin 0.6s linear infinite;
- }
-
- @keyframes spin {
- to {
- transform: rotate(360deg);
- }
- }
-
- .spinner-text {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .error-section {
- display: flex;
- flex-direction: column;
- align-items: center;
- gap: var(--padding);
- padding: calc(var(--padding) * 2) 0;
- }
-
- .empty-text {
- color: var(--gray);
- font-size: 14.5px;
- text-align: center;
- padding: calc(var(--padding) * 4) 0;
- }
-</style>
diff --git a/src/routes/courses/cakto/+page.svelte b/src/routes/courses/cakto/+page.svelte
deleted file mode 100644
index dafe0d96..00000000
--- a/src/routes/courses/cakto/+page.svelte
+++ /dev/null
@@ -1,693 +0,0 @@
-<script lang="ts">
- import { pluginInvoke } from "$lib/plugin-invoke";
- import { open } from "@tauri-apps/plugin-dialog";
- import CourseCard from "$components/hotmart/CourseCard.svelte";
- import { showToast } from "$lib/stores/toast-store.svelte";
- import { getDownloads } from "$lib/stores/download-store.svelte";
- import { getSettings } from "$lib/stores/settings-store.svelte";
- import { t } from "$lib/i18n";
-
- let downloads = $derived(getDownloads());
-
- type CaktoCourse = {
- id: string;
- name: string;
- image_url: string | null;
- };
-
- let email = $state("");
- let password = $state("");
- let token = $state("");
- let fileInput: HTMLInputElement = $state() as HTMLInputElement;
- function onFileSelected(e: Event) {
- const input = e.target as HTMLInputElement;
- const file = input.files?.[0];
- if (!file) return;
- const reader = new FileReader();
- reader.onload = () => { token = reader.result as string; };
- reader.readAsText(file);
- input.value = "";
- }
- let loading = $state(false);
- let error = $state("");
-
- let checking = $state(true);
- let loggedIn = $state(false);
- let sessionEmail = $state("");
-
- let loginMode = $state<"credentials" | "token">("credentials");
-
- let courses: CaktoCourse[] = $state([]);
- let loadingCourses = $state(false);
- let coursesError = $state("");
-
- const ITEMS_PER_PAGE = 12;
- let currentPage = $state(1);
-
- let totalPages = $derived(Math.max(1, Math.ceil(courses.length / ITEMS_PER_PAGE)));
- let paginatedCourses = $derived(
- courses.slice((currentPage - 1) * ITEMS_PER_PAGE, currentPage * ITEMS_PER_PAGE)
- );
-
- let pageNumbers = $derived((): number[] => {
- const pages: number[] = [];
- if (totalPages <= 7) {
- for (let i = 1; i <= totalPages; i++) pages.push(i);
- } else {
- pages.push(1);
- if (currentPage > 3) pages.push(-1);
- const start = Math.max(2, currentPage - 1);
- const end = Math.min(totalPages - 1, currentPage + 1);
- for (let i = start; i <= end; i++) pages.push(i);
- if (currentPage < totalPages - 2) pages.push(-1);
- pages.push(totalPages);
- }
- return pages;
- });
-
- function goToPage(page: number) {
- if (page >= 1 && page <= totalPages) {
- currentPage = page;
- }
- }
-
- $effect(() => {
- checkSession();
- });
-
- async function checkSession() {
- try {
- const result = await pluginInvoke<string>("courses", "cakto_check_session");
- sessionEmail = result;
- loggedIn = true;
- loadCourses();
- } catch {
- loggedIn = false;
- } finally {
- checking = false;
- }
- }
-
- async function handleLogin() {
- error = "";
- loading = true;
- try {
- const result = await pluginInvoke<string>("courses", "cakto_login", { email, password });
- sessionEmail = result || email;
- loggedIn = true;
- loadCourses();
- } catch (e: any) {
- error = typeof e === "string" ? e : e.message ?? $t('hotmart.unknown_error');
- } finally {
- loading = false;
- }
- }
-
- async function handleTokenLogin() {
- if (!token.trim()) return;
- error = "";
- loading = true;
- try {
- const result = await pluginInvoke<string>("courses", "cakto_login_token", { token: token.trim() });
- sessionEmail = result || "Token";
- loggedIn = true;
- loadCourses();
- } catch (e: any) {
- error = typeof e === "string" ? e : e.message ?? $t('hotmart.unknown_error');
- } finally {
- loading = false;
- }
- }
-
- async function handleLogout() {
- try {
- await pluginInvoke("courses", "cakto_logout");
- } catch {
- }
- loggedIn = false;
- sessionEmail = "";
- courses = [];
- coursesError = "";
- currentPage = 1;
- }
-
- async function loadCourses() {
- loadingCourses = true;
- coursesError = "";
- try {
- courses = await pluginInvoke("courses", "cakto_list_courses");
- currentPage = 1;
- } catch (e: any) {
- coursesError = typeof e === "string" ? e : e.message ?? $t('hotmart.courses_error');
- } finally {
- loadingCourses = false;
- }
- }
-
- function getCourseDownloadStatus(courseId: string): "idle" | "downloading" | "complete" | "error" {
- const numId = Number(courseId) || 0;
- const item = downloads.get(numId);
- if (!item) return "idle";
- const s = item.status;
- if (s === "queued" || s === "paused" || s === "seeding") return "downloading";
- return s;
- }
-
- function getCourseDownloadPercent(courseId: string): number {
- const numId = Number(courseId) || 0;
- return downloads.get(numId)?.percent ?? 0;
- }
-
- async function downloadCourse(course: CaktoCourse) {
- const status = getCourseDownloadStatus(course.id);
- if (status === "downloading") {
- showToast("info", $t("toast.download_already_active"));
- return;
- }
- if (status === "complete") return;
-
- const appSettings = getSettings();
- let outputDir: string | null = null;
-
- if (appSettings?.download.always_ask_path) {
- outputDir = await open({ directory: true, title: $t("hotmart.choose_folder") }) as string | null;
- if (!outputDir) return;
- } else {
- outputDir = appSettings?.download.default_output_dir ?? null;
- if (!outputDir) {
- outputDir = await open({ directory: true, title: $t("hotmart.choose_folder") }) as string | null;
- if (!outputDir) return;
- }
- }
-
- try {
- await pluginInvoke("courses", "start_cakto_download", {
- courseJson: JSON.stringify(course),
- outputDir,
- });
- showToast("info", $t("toast.download_preparing"));
- } catch (e: any) {
- const msg = typeof e === "string" ? e : e.message ?? $t("common.error");
- showToast("error", msg);
- }
- }
-
- let refreshing = $state(false);
-
- async function refreshCourses() {
- refreshing = true;
- loadingCourses = true;
- coursesError = "";
- try {
- courses = await pluginInvoke("courses", "cakto_refresh_courses");
- currentPage = 1;
- } catch (e: any) {
- coursesError = typeof e === "string" ? e : e.message ?? $t('hotmart.courses_error');
- } finally {
- loadingCourses = false;
- refreshing = false;
- }
- }
-</script>
-
-<a href="/courses" class="back-link">
- <svg viewBox="0 0 24 24" width="16" height="16" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
- <path d="M19 12H5" />
- <path d="M12 19l-7-7 7-7" />
- </svg>
- {$t("courses.back")}
-</a>
-
-{#if checking}
- <div class="page-center">
- <span class="spinner"></span>
- <span class="spinner-text">{$t('hotmart.checking_session')}</span>
- </div>
-{:else if loggedIn}
- <div class="page-logged">
- <div class="session-bar">
- <span class="session-info">
- {$t('hotmart.logged_as', { email: sessionEmail || "—" })}
- </span>
- <div class="session-actions">
- <button
- class="button"
- onclick={refreshCourses}
- disabled={refreshing}
- aria-label={$t('hotmart.refresh')}
- >
- <svg viewBox="0 0 24 24" width="14" height="14" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class:spinning={refreshing}>
- <path d="M21 2v6h-6" />
- <path d="M3 12a9 9 0 0115-6.7L21 8" />
- <path d="M3 22v-6h6" />
- <path d="M21 12a9 9 0 01-15 6.7L3 16" />
- </svg>
- </button>
- <button class="button" onclick={handleLogout}>{$t('hotmart.logout')}</button>
- </div>
- </div>
-
- {#if loadingCourses}
- <div class="spinner-section">
- <span class="spinner"></span>
- <span class="spinner-text">{$t('hotmart.loading_courses')}</span>
- </div>
- {:else if coursesError}
- <div class="error-section">
- <p class="error-msg">{coursesError}</p>
- <button class="button" onclick={loadCourses}>{$t('common.retry')}</button>
- </div>
- {:else if courses.length === 0}
- <p class="empty-text">{$t('hotmart.no_courses')}</p>
- {:else}
- <div class="courses-header">
- <h2>{$t('hotmart.courses_title')}</h2>
- <span class="subtext">{courses.length === 1 ? $t('hotmart.course_count_one', { count: courses.length }) : $t('hotmart.course_count', { count: courses.length })}</span>
- </div>
-
- <div class="courses-grid">
- {#each paginatedCourses as course (course.id)}
- <CourseCard
- name={course.name}
- price=""
- imageUrl={course.image_url ?? undefined}
- downloadStatus={getCourseDownloadStatus(course.id)}
- downloadPercent={getCourseDownloadPercent(course.id)}
- onDownload={() => downloadCourse(course)}
- />
- {/each}
- </div>
-
- {#if totalPages > 1}
- <div class="pagination">
- <span class="pagination-info">
- {$t('hotmart.page_of', { current: currentPage, total: totalPages })} &middot; {courses.length === 1 ? $t('hotmart.course_count_one', { count: courses.length }) : $t('hotmart.course_count', { count: courses.length })}
- </span>
- <div class="pagination-controls">
- <button
- class="button pagination-btn"
- disabled={currentPage <= 1}
- onclick={() => goToPage(currentPage - 1)}
- >
- &lt;
- </button>
-
- {#each pageNumbers() as page}
- {#if page === -1}
- <span class="pagination-ellipsis">&hellip;</span>
- {:else}
- <button
- class="button pagination-btn"
- class:active={page === currentPage}
- onclick={() => goToPage(page)}
- >
- {page}
- </button>
- {/if}
- {/each}
-
- <button
- class="button pagination-btn"
- disabled={currentPage >= totalPages}
- onclick={() => goToPage(currentPage + 1)}
- >
- &gt;
- </button>
- </div>
- </div>
- {/if}
- {/if}
- </div>
-{:else}
- <div class="page-center">
- <div class="login-card">
- <h2>Cakto</h2>
-
- <div class="login-tabs">
- <button
- class="button login-tab"
- class:active={loginMode === "credentials"}
- onclick={() => { loginMode = "credentials"; error = ""; }}
- >
- Email & Password
- </button>
- <button
- class="button login-tab"
- class:active={loginMode === "token"}
- onclick={() => { loginMode = "token"; error = ""; }}
- >
- Cookie
- </button>
- </div>
-
- {#if loginMode === "credentials"}
- <form class="form" onsubmit={(e) => { e.preventDefault(); handleLogin(); }}>
- <label class="field">
- <span class="field-label">{$t('hotmart.email_label')}</span>
- <input
- type="email"
- placeholder={$t('hotmart.email_placeholder')}
- bind:value={email}
- class="input"
- disabled={loading}
- required
- />
- </label>
- <label class="field">
- <span class="field-label">{$t('hotmart.password_label')}</span>
- <input
- type="password"
- placeholder={$t('hotmart.password_placeholder')}
- bind:value={password}
- class="input"
- disabled={loading}
- required
- />
- </label>
-
- {#if error}
- <p class="error-msg">{error}</p>
- {/if}
-
- <button type="submit" class="button" disabled={loading}>
- {#if loading}
- {$t('hotmart.authenticating')}
- {:else}
- {$t('hotmart.login')}
- {/if}
- </button>
- </form>
- {:else}
- <div class="form">
- <label class="field">
- <span class="field-label">Cookies JSON</span>
- <textarea
- class="input token-textarea"
- placeholder="Paste cookies JSON from browser extension or a raw token"
- bind:value={token}
- disabled={loading}
- rows="4"
- ></textarea>
- </label>
- <input type="file" accept=".json,.txt" class="hidden-file-input" bind:this={fileInput} onchange={onFileSelected} />
- <button class="button" onclick={() => fileInput?.click()} disabled={loading}>Import .json file</button>
-
- {#if error}
- <p class="error-msg">{error}</p>
- {/if}
-
- <button class="button" onclick={handleTokenLogin} disabled={loading || !token.trim()}>
- {#if loading}
- {$t('hotmart.authenticating')}
- {:else}
- {$t('hotmart.login')}
- {/if}
- </button>
- </div>
- {/if}
- </div>
- </div>
-{/if}
-
-<style>
- .back-link {
- display: inline-flex;
- align-items: center;
- gap: 6px;
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- margin-bottom: var(--padding);
- }
-
- @media (hover: hover) {
- .back-link:hover {
- color: var(--secondary);
- }
- }
-
- .page-center {
- display: flex;
- flex-direction: column;
- align-items: center;
- justify-content: center;
- min-height: calc(100vh - var(--padding) * 4 - 40px);
- gap: var(--padding);
- }
-
- .page-logged {
- display: flex;
- flex-direction: column;
- align-items: center;
- gap: calc(var(--padding) * 1.5);
- padding: calc(var(--padding) * 1.5);
- width: 100%;
- }
-
- .page-logged > :global(*) {
- width: 100%;
- max-width: 1200px;
- }
-
- .session-bar {
- display: flex;
- align-items: center;
- justify-content: space-between;
- }
-
- .session-info {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .session-actions {
- display: flex;
- gap: calc(var(--padding) / 2);
- }
-
- .session-bar :global(.button) {
- padding: calc(var(--padding) / 2) var(--padding);
- font-size: 12.5px;
- }
-
- .spinning {
- animation: spin 0.6s linear infinite;
- }
-
- .courses-header {
- display: flex;
- align-items: baseline;
- gap: var(--padding);
- }
-
- .courses-header h2 {
- margin-block: 0;
- }
-
- .subtext {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .courses-grid {
- display: grid;
- grid-template-columns: repeat(4, 1fr);
- gap: var(--padding);
- }
-
- @media (max-width: 1000px) {
- .courses-grid {
- grid-template-columns: repeat(3, 1fr);
- }
- }
-
- @media (max-width: 750px) {
- .courses-grid {
- grid-template-columns: repeat(2, 1fr);
- }
- }
-
- @media (max-width: 535px) {
- .courses-grid {
- grid-template-columns: 1fr;
- }
- }
-
- .pagination {
- display: flex;
- flex-direction: column;
- align-items: center;
- gap: var(--padding);
- padding-top: var(--padding);
- }
-
- .pagination-info {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .pagination-controls {
- display: flex;
- align-items: center;
- gap: calc(var(--padding) / 3);
- }
-
- .pagination-btn {
- min-width: 36px;
- height: 36px;
- padding: 0;
- display: flex;
- align-items: center;
- justify-content: center;
- font-size: 14.5px;
- }
-
- .pagination-ellipsis {
- min-width: 36px;
- text-align: center;
- color: var(--gray);
- font-size: 14.5px;
- }
-
- .login-card {
- width: 100%;
- max-width: 400px;
- background: var(--button-elevated);
- border-radius: var(--border-radius);
- padding: calc(var(--padding) * 2);
- display: flex;
- flex-direction: column;
- gap: calc(var(--padding) * 1.5);
- }
-
- .login-card h2 {
- margin-block: 0;
- }
-
- .login-tabs {
- display: flex;
- gap: 0;
- }
-
- .login-tab {
- flex: 1;
- border-radius: 0;
- font-size: 12.5px;
- padding: calc(var(--padding) * 0.75) var(--padding);
- }
-
- .login-tab:first-child {
- border-radius: var(--border-radius) 0 0 var(--border-radius);
- }
-
- .login-tab:last-child {
- border-radius: 0 var(--border-radius) var(--border-radius) 0;
- }
-
- .hidden-file-input {
- display: none;
- }
-
- .token-textarea {
- resize: vertical;
- min-height: 80px;
- font-size: 11.5px;
- font-family: var(--font-mono);
- line-height: 1.5;
- }
-
- .form {
- display: flex;
- flex-direction: column;
- gap: var(--padding);
- }
-
- .field {
- display: flex;
- flex-direction: column;
- gap: calc(var(--padding) / 2);
- }
-
- .field-label {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .input {
- width: 100%;
- padding: var(--padding);
- font-size: 14.5px;
- background: var(--button);
- border-radius: var(--border-radius);
- color: var(--secondary);
- border: 1px solid var(--input-border);
- }
-
- .input::placeholder {
- color: var(--gray);
- }
-
- .input:focus-visible {
- border-color: var(--secondary);
- outline: none;
- }
-
- .input:disabled {
- opacity: 0.5;
- cursor: default;
- }
-
- .error-msg {
- color: var(--red);
- font-size: 12.5px;
- font-weight: 500;
- }
-
- .spinner-section {
- display: flex;
- flex-direction: column;
- align-items: center;
- gap: var(--padding);
- padding: calc(var(--padding) * 4) 0;
- }
-
- .spinner {
- width: 24px;
- height: 24px;
- border: 2px solid var(--input-border);
- border-top-color: var(--blue);
- border-radius: 50%;
- animation: spin 0.6s linear infinite;
- }
-
- @keyframes spin {
- to {
- transform: rotate(360deg);
- }
- }
-
- .spinner-text {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .error-section {
- display: flex;
- flex-direction: column;
- align-items: center;
- gap: var(--padding);
- padding: calc(var(--padding) * 2) 0;
- }
-
- .empty-text {
- color: var(--gray);
- font-size: 14.5px;
- text-align: center;
- padding: calc(var(--padding) * 4) 0;
- }
-</style>
\ No newline at end of file
diff --git a/src/routes/courses/caktomembers/+page.svelte b/src/routes/courses/caktomembers/+page.svelte
deleted file mode 100644
index fb6bff80..00000000
--- a/src/routes/courses/caktomembers/+page.svelte
+++ /dev/null
@@ -1,596 +0,0 @@
-<script lang="ts">
- import { pluginInvoke } from "$lib/plugin-invoke";
- import { open } from "@tauri-apps/plugin-dialog";
- import CourseCard from "$components/hotmart/CourseCard.svelte";
- import { showToast } from "$lib/stores/toast-store.svelte";
- import { getDownloads } from "$lib/stores/download-store.svelte";
- import { getSettings } from "$lib/stores/settings-store.svelte";
- import { t } from "$lib/i18n";
-
- let downloads = $derived(getDownloads());
-
- type CaktoMembersCourse = {
- id: string;
- name: string;
- };
-
- let token = $state("");
- let fileInput: HTMLInputElement = $state() as HTMLInputElement;
- function onFileSelected(e: Event) {
- const input = e.target as HTMLInputElement;
- const file = input.files?.[0];
- if (!file) return;
- const reader = new FileReader();
- reader.onload = () => { token = reader.result as string; };
- reader.readAsText(file);
- input.value = "";
- }
- let loading = $state(false);
- let error = $state("");
-
- let checking = $state(true);
- let loggedIn = $state(false);
- let sessionEmail = $state("");
-
- let courses: CaktoMembersCourse[] = $state([]);
- let loadingCourses = $state(false);
- let coursesError = $state("");
-
- const ITEMS_PER_PAGE = 12;
- let currentPage = $state(1);
-
- let totalPages = $derived(Math.max(1, Math.ceil(courses.length / ITEMS_PER_PAGE)));
- let paginatedCourses = $derived(
- courses.slice((currentPage - 1) * ITEMS_PER_PAGE, currentPage * ITEMS_PER_PAGE)
- );
-
- let pageNumbers = $derived((): number[] => {
- const pages: number[] = [];
- if (totalPages <= 7) {
- for (let i = 1; i <= totalPages; i++) pages.push(i);
- } else {
- pages.push(1);
- if (currentPage > 3) pages.push(-1);
- const start = Math.max(2, currentPage - 1);
- const end = Math.min(totalPages - 1, currentPage + 1);
- for (let i = start; i <= end; i++) pages.push(i);
- if (currentPage < totalPages - 2) pages.push(-1);
- pages.push(totalPages);
- }
- return pages;
- });
-
- function goToPage(page: number) {
- if (page >= 1 && page <= totalPages) {
- currentPage = page;
- }
- }
-
- $effect(() => {
- checkSession();
- });
-
- async function checkSession() {
- try {
- const result = await pluginInvoke<string>("courses", "caktomembers_check_session");
- sessionEmail = result;
- loggedIn = true;
- loadCourses();
- } catch {
- loggedIn = false;
- } finally {
- checking = false;
- }
- }
-
- async function handleTokenLogin() {
- if (!token.trim()) return;
- error = "";
- loading = true;
- try {
- const result = await pluginInvoke<string>("courses", "caktomembers_login_token", { token: token.trim() });
- sessionEmail = result || "Token";
- loggedIn = true;
- loadCourses();
- } catch (e: any) {
- error = typeof e === "string" ? e : e.message ?? $t('hotmart.unknown_error');
- } finally {
- loading = false;
- }
- }
-
- async function handleLogout() {
- try {
- await pluginInvoke("courses", "caktomembers_logout");
- } catch {
- }
- loggedIn = false;
- sessionEmail = "";
- courses = [];
- coursesError = "";
- currentPage = 1;
- }
-
- async function loadCourses() {
- loadingCourses = true;
- coursesError = "";
- try {
- courses = await pluginInvoke("courses", "caktomembers_list_courses");
- currentPage = 1;
- } catch (e: any) {
- coursesError = typeof e === "string" ? e : e.message ?? $t('hotmart.courses_error');
- } finally {
- loadingCourses = false;
- }
- }
-
- function getCourseDownloadStatus(courseId: string): "idle" | "downloading" | "complete" | "error" {
- const numId = Number(courseId) || 0;
- const item = downloads.get(numId);
- if (!item) return "idle";
- const s = item.status;
- if (s === "queued" || s === "paused" || s === "seeding") return "downloading";
- return s;
- }
-
- function getCourseDownloadPercent(courseId: string): number {
- const numId = Number(courseId) || 0;
- return downloads.get(numId)?.percent ?? 0;
- }
-
- async function downloadCourse(course: CaktoMembersCourse) {
- const status = getCourseDownloadStatus(course.id);
- if (status === "downloading") {
- showToast("info", $t("toast.download_already_active"));
- return;
- }
- if (status === "complete") return;
-
- const appSettings = getSettings();
- let outputDir: string | null = null;
-
- if (appSettings?.download.always_ask_path) {
- outputDir = await open({ directory: true, title: $t("hotmart.choose_folder") }) as string | null;
- if (!outputDir) return;
- } else {
- outputDir = appSettings?.download.default_output_dir ?? null;
- if (!outputDir) {
- outputDir = await open({ directory: true, title: $t("hotmart.choose_folder") }) as string | null;
- if (!outputDir) return;
- }
- }
-
- try {
- await pluginInvoke("courses", "start_caktomembers_download", {
- courseJson: JSON.stringify(course),
- outputDir,
- });
- showToast("info", $t("toast.download_preparing"));
- } catch (e: any) {
- const msg = typeof e === "string" ? e : e.message ?? $t("common.error");
- showToast("error", msg);
- }
- }
-
- let refreshing = $state(false);
-
- async function refreshCourses() {
- refreshing = true;
- loadingCourses = true;
- coursesError = "";
- try {
- courses = await pluginInvoke("courses", "caktomembers_refresh_courses");
- currentPage = 1;
- } catch (e: any) {
- coursesError = typeof e === "string" ? e : e.message ?? $t('hotmart.courses_error');
- } finally {
- loadingCourses = false;
- refreshing = false;
- }
- }
-</script>
-
-<a href="/courses" class="back-link">
- <svg viewBox="0 0 24 24" width="16" height="16" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
- <path d="M19 12H5" />
- <path d="M12 19l-7-7 7-7" />
- </svg>
- {$t("courses.back")}
-</a>
-
-{#if checking}
- <div class="page-center">
- <span class="spinner"></span>
- <span class="spinner-text">{$t('hotmart.checking_session')}</span>
- </div>
-{:else if loggedIn}
- <div class="page-logged">
- <div class="session-bar">
- <span class="session-info">
- {$t('hotmart.logged_as', { email: sessionEmail || "—" })}
- </span>
- <div class="session-actions">
- <button
- class="button"
- onclick={refreshCourses}
- disabled={refreshing}
- aria-label={$t('hotmart.refresh')}
- >
- <svg viewBox="0 0 24 24" width="14" height="14" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class:spinning={refreshing}>
- <path d="M21 2v6h-6" />
- <path d="M3 12a9 9 0 0115-6.7L21 8" />
- <path d="M3 22v-6h6" />
- <path d="M21 12a9 9 0 01-15 6.7L3 16" />
- </svg>
- </button>
- <button class="button" onclick={handleLogout}>{$t('hotmart.logout')}</button>
- </div>
- </div>
-
- {#if loadingCourses}
- <div class="spinner-section">
- <span class="spinner"></span>
- <span class="spinner-text">{$t('hotmart.loading_courses')}</span>
- </div>
- {:else if coursesError}
- <div class="error-section">
- <p class="error-msg">{coursesError}</p>
- <button class="button" onclick={loadCourses}>{$t('common.retry')}</button>
- </div>
- {:else if courses.length === 0}
- <p class="empty-text">{$t('hotmart.no_courses')}</p>
- {:else}
- <div class="courses-header">
- <h2>{$t('hotmart.courses_title')}</h2>
- <span class="subtext">{courses.length === 1 ? $t('hotmart.course_count_one', { count: courses.length }) : $t('hotmart.course_count', { count: courses.length })}</span>
- </div>
-
- <div class="courses-grid">
- {#each paginatedCourses as course (course.id)}
- <CourseCard
- name={course.name}
- price=""
- downloadStatus={getCourseDownloadStatus(course.id)}
- downloadPercent={getCourseDownloadPercent(course.id)}
- onDownload={() => downloadCourse(course)}
- />
- {/each}
- </div>
-
- {#if totalPages > 1}
- <div class="pagination">
- <span class="pagination-info">
- {$t('hotmart.page_of', { current: currentPage, total: totalPages })} &middot; {courses.length === 1 ? $t('hotmart.course_count_one', { count: courses.length }) : $t('hotmart.course_count', { count: courses.length })}
- </span>
- <div class="pagination-controls">
- <button
- class="button pagination-btn"
- disabled={currentPage <= 1}
- onclick={() => goToPage(currentPage - 1)}
- >
- &lt;
- </button>
-
- {#each pageNumbers() as page}
- {#if page === -1}
- <span class="pagination-ellipsis">&hellip;</span>
- {:else}
- <button
- class="button pagination-btn"
- class:active={page === currentPage}
- onclick={() => goToPage(page)}
- >
- {page}
- </button>
- {/if}
- {/each}
-
- <button
- class="button pagination-btn"
- disabled={currentPage >= totalPages}
- onclick={() => goToPage(currentPage + 1)}
- >
- &gt;
- </button>
- </div>
- </div>
- {/if}
- {/if}
- </div>
-{:else}
- <div class="page-center">
- <div class="login-card">
- <h2>Cakto Members</h2>
-
- <div class="form">
- <label class="field">
- <span class="field-label">Cookies JSON</span>
- <textarea
- class="input token-textarea"
- placeholder="Paste cookies JSON from browser extension or a raw token"
- bind:value={token}
- disabled={loading}
- rows="4"
- ></textarea>
- </label>
- <input type="file" accept=".json,.txt" class="hidden-file-input" bind:this={fileInput} onchange={onFileSelected} />
- <button class="button" onclick={() => fileInput?.click()} disabled={loading}>Import .json file</button>
-
- {#if error}
- <p class="error-msg">{error}</p>
- {/if}
-
- <button class="button" onclick={handleTokenLogin} disabled={loading || !token.trim()}>
- {#if loading}
- {$t('hotmart.authenticating')}
- {:else}
- {$t('hotmart.login')}
- {/if}
- </button>
- </div>
- </div>
- </div>
-{/if}
-
-<style>
- .back-link {
- display: inline-flex;
- align-items: center;
- gap: 6px;
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- margin-bottom: var(--padding);
- }
-
- @media (hover: hover) {
- .back-link:hover {
- color: var(--secondary);
- }
- }
-
- .page-center {
- display: flex;
- flex-direction: column;
- align-items: center;
- justify-content: center;
- min-height: calc(100vh - var(--padding) * 4 - 40px);
- gap: var(--padding);
- }
-
- .page-logged {
- display: flex;
- flex-direction: column;
- align-items: center;
- gap: calc(var(--padding) * 1.5);
- padding: calc(var(--padding) * 1.5);
- width: 100%;
- }
-
- .page-logged > :global(*) {
- width: 100%;
- max-width: 1200px;
- }
-
- .session-bar {
- display: flex;
- align-items: center;
- justify-content: space-between;
- }
-
- .session-info {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .session-actions {
- display: flex;
- gap: calc(var(--padding) / 2);
- }
-
- .session-bar :global(.button) {
- padding: calc(var(--padding) / 2) var(--padding);
- font-size: 12.5px;
- }
-
- .spinning {
- animation: spin 0.6s linear infinite;
- }
-
- .courses-header {
- display: flex;
- align-items: baseline;
- gap: var(--padding);
- }
-
- .courses-header h2 {
- margin-block: 0;
- }
-
- .subtext {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .courses-grid {
- display: grid;
- grid-template-columns: repeat(4, 1fr);
- gap: var(--padding);
- }
-
- @media (max-width: 1000px) {
- .courses-grid {
- grid-template-columns: repeat(3, 1fr);
- }
- }
-
- @media (max-width: 750px) {
- .courses-grid {
- grid-template-columns: repeat(2, 1fr);
- }
- }
-
- @media (max-width: 535px) {
- .courses-grid {
- grid-template-columns: 1fr;
- }
- }
-
- .pagination {
- display: flex;
- flex-direction: column;
- align-items: center;
- gap: var(--padding);
- padding-top: var(--padding);
- }
-
- .pagination-info {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .pagination-controls {
- display: flex;
- align-items: center;
- gap: calc(var(--padding) / 3);
- }
-
- .pagination-btn {
- min-width: 36px;
- height: 36px;
- padding: 0;
- display: flex;
- align-items: center;
- justify-content: center;
- font-size: 14.5px;
- }
-
- .pagination-ellipsis {
- min-width: 36px;
- text-align: center;
- color: var(--gray);
- font-size: 14.5px;
- }
-
- .login-card {
- width: 100%;
- max-width: 400px;
- background: var(--button-elevated);
- border-radius: var(--border-radius);
- padding: calc(var(--padding) * 2);
- display: flex;
- flex-direction: column;
- gap: calc(var(--padding) * 1.5);
- }
-
- .login-card h2 {
- margin-block: 0;
- }
-
- .hidden-file-input {
- display: none;
- }
-
- .token-textarea {
- resize: vertical;
- min-height: 80px;
- font-size: 11.5px;
- font-family: var(--font-mono);
- line-height: 1.5;
- }
-
- .form {
- display: flex;
- flex-direction: column;
- gap: var(--padding);
- }
-
- .field {
- display: flex;
- flex-direction: column;
- gap: calc(var(--padding) / 2);
- }
-
- .field-label {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .input {
- width: 100%;
- padding: var(--padding);
- font-size: 14.5px;
- background: var(--button);
- border-radius: var(--border-radius);
- color: var(--secondary);
- border: 1px solid var(--input-border);
- }
-
- .input::placeholder {
- color: var(--gray);
- }
-
- .input:focus-visible {
- border-color: var(--secondary);
- outline: none;
- }
-
- .input:disabled {
- opacity: 0.5;
- cursor: default;
- }
-
- .error-msg {
- color: var(--red);
- font-size: 12.5px;
- font-weight: 500;
- }
-
- .spinner-section {
- display: flex;
- flex-direction: column;
- align-items: center;
- gap: var(--padding);
- padding: calc(var(--padding) * 4) 0;
- }
-
- .spinner {
- width: 24px;
- height: 24px;
- border: 2px solid var(--input-border);
- border-top-color: var(--blue);
- border-radius: 50%;
- animation: spin 0.6s linear infinite;
- }
-
- @keyframes spin {
- to {
- transform: rotate(360deg);
- }
- }
-
- .spinner-text {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .error-section {
- display: flex;
- flex-direction: column;
- align-items: center;
- gap: var(--padding);
- padding: calc(var(--padding) * 2) 0;
- }
-
- .empty-text {
- color: var(--gray);
- font-size: 14.5px;
- text-align: center;
- padding: calc(var(--padding) * 4) 0;
- }
-</style>
\ No newline at end of file
diff --git a/src/routes/courses/curseduca/+page.svelte b/src/routes/courses/curseduca/+page.svelte
deleted file mode 100644
index 98e37d8d..00000000
--- a/src/routes/courses/curseduca/+page.svelte
+++ /dev/null
@@ -1,724 +0,0 @@
-<script lang="ts">
- import { pluginInvoke } from "$lib/plugin-invoke";
- import { open } from "@tauri-apps/plugin-dialog";
- import CourseCard from "$components/hotmart/CourseCard.svelte";
- import { showToast } from "$lib/stores/toast-store.svelte";
- import { getDownloads } from "$lib/stores/download-store.svelte";
- import { getSettings } from "$lib/stores/settings-store.svelte";
- import { t } from "$lib/i18n";
-
- let downloads = $derived(getDownloads());
-
- type CurseducaCourse = {
- id: string;
- name: string;
- slug: string;
- };
-
- let email = $state("");
- let password = $state("");
- let token = $state("");
- let fileInput: HTMLInputElement = $state() as HTMLInputElement;
- function onFileSelected(e: Event) {
- const input = e.target as HTMLInputElement;
- const file = input.files?.[0];
- if (!file) return;
- const reader = new FileReader();
- reader.onload = () => { token = reader.result as string; };
- reader.readAsText(file);
- input.value = "";
- }
- let apiKey = $state("");
- let siteUrl = $state("");
- let loading = $state(false);
- let error = $state("");
-
- let checking = $state(true);
- let loggedIn = $state(false);
- let sessionEmail = $state("");
-
- let loginMode = $state<"credentials" | "token">("credentials");
-
- let courses: CurseducaCourse[] = $state([]);
- let loadingCourses = $state(false);
- let coursesError = $state("");
-
- const ITEMS_PER_PAGE = 12;
- let currentPage = $state(1);
-
- let totalPages = $derived(Math.max(1, Math.ceil(courses.length / ITEMS_PER_PAGE)));
- let paginatedCourses = $derived(
- courses.slice((currentPage - 1) * ITEMS_PER_PAGE, currentPage * ITEMS_PER_PAGE)
- );
-
- let pageNumbers = $derived((): number[] => {
- const pages: number[] = [];
- if (totalPages <= 7) {
- for (let i = 1; i <= totalPages; i++) pages.push(i);
- } else {
- pages.push(1);
- if (currentPage > 3) pages.push(-1);
- const start = Math.max(2, currentPage - 1);
- const end = Math.min(totalPages - 1, currentPage + 1);
- for (let i = start; i <= end; i++) pages.push(i);
- if (currentPage < totalPages - 2) pages.push(-1);
- pages.push(totalPages);
- }
- return pages;
- });
-
- function goToPage(page: number) {
- if (page >= 1 && page <= totalPages) {
- currentPage = page;
- }
- }
-
- $effect(() => {
- checkSession();
- });
-
- async function checkSession() {
- try {
- const result = await pluginInvoke<string>("courses", "curseduca_check_session");
- sessionEmail = result;
- loggedIn = true;
- loadCourses();
- } catch {
- loggedIn = false;
- } finally {
- checking = false;
- }
- }
-
- async function handleLogin() {
- error = "";
- loading = true;
- try {
- const result = await pluginInvoke<string>("courses", "curseduca_login", { email, password, siteUrl });
- sessionEmail = result || email;
- loggedIn = true;
- loadCourses();
- } catch (e: any) {
- error = typeof e === "string" ? e : e.message ?? $t('hotmart.unknown_error');
- } finally {
- loading = false;
- }
- }
-
- async function handleTokenLogin() {
- if (!token.trim()) return;
- error = "";
- loading = true;
- try {
- const result = await pluginInvoke<string>("courses", "curseduca_login_token", { token: token.trim(), apiKey: apiKey.trim(), siteUrl });
- sessionEmail = result || "Token";
- loggedIn = true;
- loadCourses();
- } catch (e: any) {
- error = typeof e === "string" ? e : e.message ?? $t('hotmart.unknown_error');
- } finally {
- loading = false;
- }
- }
-
- async function handleLogout() {
- try {
- await pluginInvoke("courses", "curseduca_logout");
- } catch {
- }
- loggedIn = false;
- sessionEmail = "";
- courses = [];
- coursesError = "";
- currentPage = 1;
- }
-
- async function loadCourses() {
- loadingCourses = true;
- coursesError = "";
- try {
- courses = await pluginInvoke("courses", "curseduca_list_courses");
- currentPage = 1;
- } catch (e: any) {
- coursesError = typeof e === "string" ? e : e.message ?? $t('hotmart.courses_error');
- } finally {
- loadingCourses = false;
- }
- }
-
- function getCourseDownloadStatus(courseId: string): "idle" | "downloading" | "complete" | "error" {
- const numId = Number(courseId) || 0;
- const item = downloads.get(numId);
- if (!item) return "idle";
- const s = item.status;
- if (s === "queued" || s === "paused" || s === "seeding") return "downloading";
- return s;
- }
-
- function getCourseDownloadPercent(courseId: string): number {
- const numId = Number(courseId) || 0;
- return downloads.get(numId)?.percent ?? 0;
- }
-
- async function downloadCourse(course: CurseducaCourse) {
- const status = getCourseDownloadStatus(course.id);
- if (status === "downloading") {
- showToast("info", $t("toast.download_already_active"));
- return;
- }
- if (status === "complete") return;
-
- const appSettings = getSettings();
- let outputDir: string | null = null;
-
- if (appSettings?.download.always_ask_path) {
- outputDir = await open({ directory: true, title: $t("hotmart.choose_folder") }) as string | null;
- if (!outputDir) return;
- } else {
- outputDir = appSettings?.download.default_output_dir ?? null;
- if (!outputDir) {
- outputDir = await open({ directory: true, title: $t("hotmart.choose_folder") }) as string | null;
- if (!outputDir) return;
- }
- }
-
- try {
- await pluginInvoke("courses", "start_curseduca_download", {
- courseJson: JSON.stringify(course),
- outputDir,
- });
- showToast("info", $t("toast.download_preparing"));
- } catch (e: any) {
- const msg = typeof e === "string" ? e : e.message ?? $t("common.error");
- showToast("error", msg);
- }
- }
-
- let refreshing = $state(false);
-
- async function refreshCourses() {
- refreshing = true;
- loadingCourses = true;
- coursesError = "";
- try {
- courses = await pluginInvoke("courses", "curseduca_refresh_courses");
- currentPage = 1;
- } catch (e: any) {
- coursesError = typeof e === "string" ? e : e.message ?? $t('hotmart.courses_error');
- } finally {
- loadingCourses = false;
- refreshing = false;
- }
- }
-</script>
-
-<a href="/courses" class="back-link">
- <svg viewBox="0 0 24 24" width="16" height="16" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
- <path d="M19 12H5" />
- <path d="M12 19l-7-7 7-7" />
- </svg>
- {$t("courses.back")}
-</a>
-
-{#if checking}
- <div class="page-center">
- <span class="spinner"></span>
- <span class="spinner-text">{$t('hotmart.checking_session')}</span>
- </div>
-{:else if loggedIn}
- <div class="page-logged">
- <div class="session-bar">
- <span class="session-info">
- {$t('hotmart.logged_as', { email: sessionEmail || "—" })}
- </span>
- <div class="session-actions">
- <button
- class="button"
- onclick={refreshCourses}
- disabled={refreshing}
- aria-label={$t('hotmart.refresh')}
- >
- <svg viewBox="0 0 24 24" width="14" height="14" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class:spinning={refreshing}>
- <path d="M21 2v6h-6" />
- <path d="M3 12a9 9 0 0115-6.7L21 8" />
- <path d="M3 22v-6h6" />
- <path d="M21 12a9 9 0 01-15 6.7L3 16" />
- </svg>
- </button>
- <button class="button" onclick={handleLogout}>{$t('hotmart.logout')}</button>
- </div>
- </div>
-
- {#if loadingCourses}
- <div class="spinner-section">
- <span class="spinner"></span>
- <span class="spinner-text">{$t('hotmart.loading_courses')}</span>
- </div>
- {:else if coursesError}
- <div class="error-section">
- <p class="error-msg">{coursesError}</p>
- <button class="button" onclick={loadCourses}>{$t('common.retry')}</button>
- </div>
- {:else if courses.length === 0}
- <p class="empty-text">{$t('hotmart.no_courses')}</p>
- {:else}
- <div class="courses-header">
- <h2>{$t('hotmart.courses_title')}</h2>
- <span class="subtext">{courses.length === 1 ? $t('hotmart.course_count_one', { count: courses.length }) : $t('hotmart.course_count', { count: courses.length })}</span>
- </div>
-
- <div class="courses-grid">
- {#each paginatedCourses as course (course.id)}
- <CourseCard
- name={course.name}
- price=""
- downloadStatus={getCourseDownloadStatus(course.id)}
- downloadPercent={getCourseDownloadPercent(course.id)}
- onDownload={() => downloadCourse(course)}
- />
- {/each}
- </div>
-
- {#if totalPages > 1}
- <div class="pagination">
- <span class="pagination-info">
- {$t('hotmart.page_of', { current: currentPage, total: totalPages })} &middot; {courses.length === 1 ? $t('hotmart.course_count_one', { count: courses.length }) : $t('hotmart.course_count', { count: courses.length })}
- </span>
- <div class="pagination-controls">
- <button
- class="button pagination-btn"
- disabled={currentPage <= 1}
- onclick={() => goToPage(currentPage - 1)}
- >
- &lt;
- </button>
-
- {#each pageNumbers() as page}
- {#if page === -1}
- <span class="pagination-ellipsis">&hellip;</span>
- {:else}
- <button
- class="button pagination-btn"
- class:active={page === currentPage}
- onclick={() => goToPage(page)}
- >
- {page}
- </button>
- {/if}
- {/each}
-
- <button
- class="button pagination-btn"
- disabled={currentPage >= totalPages}
- onclick={() => goToPage(currentPage + 1)}
- >
- &gt;
- </button>
- </div>
- </div>
- {/if}
- {/if}
- </div>
-{:else}
- <div class="page-center">
- <div class="login-card">
- <h2>Curseduca</h2>
-
- <div class="login-tabs">
- <button
- class="button login-tab"
- class:active={loginMode === "credentials"}
- onclick={() => { loginMode = "credentials"; error = ""; }}
- >
- Email & Password
- </button>
- <button
- class="button login-tab"
- class:active={loginMode === "token"}
- onclick={() => { loginMode = "token"; error = ""; }}
- >
- Token
- </button>
- </div>
-
- {#if loginMode === "credentials"}
- <form class="form" onsubmit={(e) => { e.preventDefault(); handleLogin(); }}>
- <label class="field">
- <span class="field-label">{$t('hotmart.email_label')}</span>
- <input
- type="email"
- placeholder={$t('hotmart.email_placeholder')}
- bind:value={email}
- class="input"
- disabled={loading}
- required
- />
- </label>
- <label class="field">
- <span class="field-label">{$t('hotmart.password_label')}</span>
- <input
- type="password"
- placeholder={$t('hotmart.password_placeholder')}
- bind:value={password}
- class="input"
- disabled={loading}
- required
- />
- </label>
- <label class="field">
- <span class="field-label">Site URL</span>
- <input
- type="url"
- placeholder="https://your-site.curseduca.pro"
- bind:value={siteUrl}
- class="input"
- disabled={loading}
- />
- </label>
-
- {#if error}
- <p class="error-msg">{error}</p>
- {/if}
-
- <button type="submit" class="button" disabled={loading}>
- {#if loading}
- {$t('hotmart.authenticating')}
- {:else}
- {$t('hotmart.login')}
- {/if}
- </button>
- </form>
- {:else}
- <div class="form">
- <label class="field">
- <span class="field-label">Cookies JSON</span>
- <textarea
- class="input token-textarea"
- placeholder="Paste cookies JSON from browser extension or a raw token"
- bind:value={token}
- disabled={loading}
- rows="4"
- ></textarea>
- </label>
- <input type="file" accept=".json,.txt" class="hidden-file-input" bind:this={fileInput} onchange={onFileSelected} />
- <button class="button" onclick={() => fileInput?.click()} disabled={loading}>Import .json file</button>
- <label class="field">
- <span class="field-label">API Key</span>
- <input
- type="text"
- placeholder="Paste your API key here..."
- bind:value={apiKey}
- class="input"
- disabled={loading}
- />
- </label>
- <label class="field">
- <span class="field-label">Site URL</span>
- <input
- type="url"
- placeholder="https://your-site.curseduca.pro"
- bind:value={siteUrl}
- class="input"
- disabled={loading}
- />
- </label>
-
- {#if error}
- <p class="error-msg">{error}</p>
- {/if}
-
- <button class="button" onclick={handleTokenLogin} disabled={loading || !token.trim()}>
- {#if loading}
- {$t('hotmart.authenticating')}
- {:else}
- {$t('hotmart.login')}
- {/if}
- </button>
- </div>
- {/if}
- </div>
- </div>
-{/if}
-
-<style>
- .back-link {
- display: inline-flex;
- align-items: center;
- gap: 6px;
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- margin-bottom: var(--padding);
- }
-
- @media (hover: hover) {
- .back-link:hover {
- color: var(--secondary);
- }
- }
-
- .page-center {
- display: flex;
- flex-direction: column;
- align-items: center;
- justify-content: center;
- min-height: calc(100vh - var(--padding) * 4 - 40px);
- gap: var(--padding);
- }
-
- .page-logged {
- display: flex;
- flex-direction: column;
- align-items: center;
- gap: calc(var(--padding) * 1.5);
- padding: calc(var(--padding) * 1.5);
- width: 100%;
- }
-
- .page-logged > :global(*) {
- width: 100%;
- max-width: 1200px;
- }
-
- .session-bar {
- display: flex;
- align-items: center;
- justify-content: space-between;
- }
-
- .session-info {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .session-actions {
- display: flex;
- gap: calc(var(--padding) / 2);
- }
-
- .session-bar :global(.button) {
- padding: calc(var(--padding) / 2) var(--padding);
- font-size: 12.5px;
- }
-
- .spinning {
- animation: spin 0.6s linear infinite;
- }
-
- .courses-header {
- display: flex;
- align-items: baseline;
- gap: var(--padding);
- }
-
- .courses-header h2 {
- margin-block: 0;
- }
-
- .subtext {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .courses-grid {
- display: grid;
- grid-template-columns: repeat(4, 1fr);
- gap: var(--padding);
- }
-
- @media (max-width: 1000px) {
- .courses-grid {
- grid-template-columns: repeat(3, 1fr);
- }
- }
-
- @media (max-width: 750px) {
- .courses-grid {
- grid-template-columns: repeat(2, 1fr);
- }
- }
-
- @media (max-width: 535px) {
- .courses-grid {
- grid-template-columns: 1fr;
- }
- }
-
- .pagination {
- display: flex;
- flex-direction: column;
- align-items: center;
- gap: var(--padding);
- padding-top: var(--padding);
- }
-
- .pagination-info {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .pagination-controls {
- display: flex;
- align-items: center;
- gap: calc(var(--padding) / 3);
- }
-
- .pagination-btn {
- min-width: 36px;
- height: 36px;
- padding: 0;
- display: flex;
- align-items: center;
- justify-content: center;
- font-size: 14.5px;
- }
-
- .pagination-ellipsis {
- min-width: 36px;
- text-align: center;
- color: var(--gray);
- font-size: 14.5px;
- }
-
- .login-card {
- width: 100%;
- max-width: 400px;
- background: var(--button-elevated);
- border-radius: var(--border-radius);
- padding: calc(var(--padding) * 2);
- display: flex;
- flex-direction: column;
- gap: calc(var(--padding) * 1.5);
- }
-
- .login-card h2 {
- margin-block: 0;
- }
-
- .login-tabs {
- display: flex;
- gap: 0;
- }
-
- .login-tab {
- flex: 1;
- border-radius: 0;
- font-size: 12.5px;
- padding: calc(var(--padding) * 0.75) var(--padding);
- }
-
- .login-tab:first-child {
- border-radius: var(--border-radius) 0 0 var(--border-radius);
- }
-
- .login-tab:last-child {
- border-radius: 0 var(--border-radius) var(--border-radius) 0;
- }
-
- .hidden-file-input {
- display: none;
- }
-
- .token-textarea {
- resize: vertical;
- min-height: 80px;
- font-size: 11.5px;
- font-family: var(--font-mono);
- line-height: 1.5;
- }
-
- .form {
- display: flex;
- flex-direction: column;
- gap: var(--padding);
- }
-
- .field {
- display: flex;
- flex-direction: column;
- gap: calc(var(--padding) / 2);
- }
-
- .field-label {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .input {
- width: 100%;
- padding: var(--padding);
- font-size: 14.5px;
- background: var(--button);
- border-radius: var(--border-radius);
- color: var(--secondary);
- border: 1px solid var(--input-border);
- }
-
- .input::placeholder {
- color: var(--gray);
- }
-
- .input:focus-visible {
- border-color: var(--secondary);
- outline: none;
- }
-
- .input:disabled {
- opacity: 0.5;
- cursor: default;
- }
-
- .error-msg {
- color: var(--red);
- font-size: 12.5px;
- font-weight: 500;
- }
-
- .spinner-section {
- display: flex;
- flex-direction: column;
- align-items: center;
- gap: var(--padding);
- padding: calc(var(--padding) * 4) 0;
- }
-
- .spinner {
- width: 24px;
- height: 24px;
- border: 2px solid var(--input-border);
- border-top-color: var(--blue);
- border-radius: 50%;
- animation: spin 0.6s linear infinite;
- }
-
- @keyframes spin {
- to {
- transform: rotate(360deg);
- }
- }
-
- .spinner-text {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .error-section {
- display: flex;
- flex-direction: column;
- align-items: center;
- gap: var(--padding);
- padding: calc(var(--padding) * 2) 0;
- }
-
- .empty-text {
- color: var(--gray);
- font-size: 14.5px;
- text-align: center;
- padding: calc(var(--padding) * 4) 0;
- }
-</style>
\ No newline at end of file
diff --git a/src/routes/courses/datascienceacademy/+page.svelte b/src/routes/courses/datascienceacademy/+page.svelte
deleted file mode 100644
index 822cdcc7..00000000
--- a/src/routes/courses/datascienceacademy/+page.svelte
+++ /dev/null
@@ -1,607 +0,0 @@
-<script lang="ts">
- import { pluginInvoke } from "$lib/plugin-invoke";
- import { open } from "@tauri-apps/plugin-dialog";
- import CourseCard from "$components/hotmart/CourseCard.svelte";
- import { showToast } from "$lib/stores/toast-store.svelte";
- import { getDownloads } from "$lib/stores/download-store.svelte";
- import { getSettings } from "$lib/stores/settings-store.svelte";
- import { t } from "$lib/i18n";
-
- let downloads = $derived(getDownloads());
-
- type DsaCourse = {
- id: string;
- name: string;
- slug: string;
- };
-
- let token = $state("");
- let loading = $state(false);
- let error = $state("");
-
- let fileInput: HTMLInputElement = $state() as HTMLInputElement;
-
- function onFileSelected(e: Event) {
- const input = e.target as HTMLInputElement;
- const file = input.files?.[0];
- if (!file) return;
- const reader = new FileReader();
- reader.onload = () => { token = reader.result as string; };
- reader.readAsText(file);
- input.value = "";
- }
-
- let checking = $state(true);
- let loggedIn = $state(false);
- let sessionEmail = $state("");
-
- let courses: DsaCourse[] = $state([]);
- let loadingCourses = $state(false);
- let coursesError = $state("");
-
- const ITEMS_PER_PAGE = 12;
- let currentPage = $state(1);
-
- let totalPages = $derived(Math.max(1, Math.ceil(courses.length / ITEMS_PER_PAGE)));
- let paginatedCourses = $derived(
- courses.slice((currentPage - 1) * ITEMS_PER_PAGE, currentPage * ITEMS_PER_PAGE)
- );
-
- let pageNumbers = $derived((): number[] => {
- const pages: number[] = [];
- if (totalPages <= 7) {
- for (let i = 1; i <= totalPages; i++) pages.push(i);
- } else {
- pages.push(1);
- if (currentPage > 3) pages.push(-1);
- const start = Math.max(2, currentPage - 1);
- const end = Math.min(totalPages - 1, currentPage + 1);
- for (let i = start; i <= end; i++) pages.push(i);
- if (currentPage < totalPages - 2) pages.push(-1);
- pages.push(totalPages);
- }
- return pages;
- });
-
- function goToPage(page: number) {
- if (page >= 1 && page <= totalPages) {
- currentPage = page;
- }
- }
-
- $effect(() => {
- checkSession();
- });
-
- async function checkSession() {
- try {
- const result = await pluginInvoke<string>("courses", "dsa_check_session");
- sessionEmail = result;
- loggedIn = true;
- loadCourses();
- } catch {
- loggedIn = false;
- } finally {
- checking = false;
- }
- }
-
- async function handleTokenLogin() {
- if (!token.trim()) return;
- error = "";
- loading = true;
- try {
- const result = await pluginInvoke<string>("courses", "dsa_login_token", { token: token.trim() });
- sessionEmail = result || "Token";
- loggedIn = true;
- loadCourses();
- } catch (e: any) {
- error = typeof e === "string" ? e : e.message ?? $t('hotmart.unknown_error');
- } finally {
- loading = false;
- }
- }
-
- async function handleLogout() {
- try {
- await pluginInvoke("courses", "dsa_logout");
- } catch {
- }
- loggedIn = false;
- sessionEmail = "";
- courses = [];
- coursesError = "";
- currentPage = 1;
- }
-
- async function loadCourses() {
- loadingCourses = true;
- coursesError = "";
- try {
- courses = await pluginInvoke("courses", "dsa_list_courses");
- currentPage = 1;
- } catch (e: any) {
- coursesError = typeof e === "string" ? e : e.message ?? $t('hotmart.courses_error');
- } finally {
- loadingCourses = false;
- }
- }
-
- function getCourseDownloadStatus(courseId: number): "idle" | "downloading" | "complete" | "error" {
- const item = downloads.get(courseId);
- if (!item) return "idle";
- const s = item.status;
- if (s === "queued" || s === "paused" || s === "seeding") return "downloading";
- return s;
- }
-
- function getCourseDownloadPercent(courseId: number): number {
- return downloads.get(courseId)?.percent ?? 0;
- }
-
- async function downloadCourse(course: DsaCourse) {
- const status = getCourseDownloadStatus(Number(course.id) || 0);
- if (status === "downloading") {
- showToast("info", $t("toast.download_already_active"));
- return;
- }
- if (status === "complete") return;
-
- const appSettings = getSettings();
- let outputDir: string | null = null;
-
- if (appSettings?.download.always_ask_path) {
- outputDir = await open({ directory: true, title: $t("hotmart.choose_folder") }) as string | null;
- if (!outputDir) return;
- } else {
- outputDir = appSettings?.download.default_output_dir ?? null;
- if (!outputDir) {
- outputDir = await open({ directory: true, title: $t("hotmart.choose_folder") }) as string | null;
- if (!outputDir) return;
- }
- }
-
- try {
- await pluginInvoke("courses", "start_dsa_course_download", {
- courseJson: JSON.stringify(course),
- outputDir,
- });
- showToast("info", $t("toast.download_preparing"));
- } catch (e: any) {
- const msg = typeof e === "string" ? e : e.message ?? $t("common.error");
- showToast("error", msg);
- }
- }
-
- let refreshing = $state(false);
-
- async function refreshCourses() {
- refreshing = true;
- loadingCourses = true;
- coursesError = "";
- try {
- courses = await pluginInvoke("courses", "dsa_refresh_courses");
- currentPage = 1;
- } catch (e: any) {
- coursesError = typeof e === "string" ? e : e.message ?? $t('hotmart.courses_error');
- } finally {
- loadingCourses = false;
- refreshing = false;
- }
- }
-</script>
-
-<a href="/courses" class="back-link">
- <svg viewBox="0 0 24 24" width="16" height="16" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
- <path d="M19 12H5" />
- <path d="M12 19l-7-7 7-7" />
- </svg>
- {$t("courses.back")}
-</a>
-
-{#if checking}
- <div class="page-center">
- <span class="spinner"></span>
- <span class="spinner-text">{$t('hotmart.checking_session')}</span>
- </div>
-{:else if loggedIn}
- <div class="page-logged">
- <div class="session-bar">
- <span class="session-info">
- {$t('hotmart.logged_as', { email: sessionEmail || "—" })}
- </span>
- <div class="session-actions">
- <button
- class="button"
- onclick={refreshCourses}
- disabled={refreshing}
- aria-label={$t('hotmart.refresh')}
- >
- <svg viewBox="0 0 24 24" width="14" height="14" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class:spinning={refreshing}>
- <path d="M21 2v6h-6" />
- <path d="M3 12a9 9 0 0115-6.7L21 8" />
- <path d="M3 22v-6h6" />
- <path d="M21 12a9 9 0 01-15 6.7L3 16" />
- </svg>
- </button>
- <button class="button" onclick={handleLogout}>{$t('hotmart.logout')}</button>
- </div>
- </div>
-
- {#if loadingCourses}
- <div class="spinner-section">
- <span class="spinner"></span>
- <span class="spinner-text">{$t('hotmart.loading_courses')}</span>
- </div>
- {:else if coursesError}
- <div class="error-section">
- <p class="error-msg">{coursesError}</p>
- <button class="button" onclick={loadCourses}>{$t('common.retry')}</button>
- </div>
- {:else if courses.length === 0}
- <p class="empty-text">{$t('hotmart.no_courses')}</p>
- {:else}
- <div class="courses-header">
- <h2>{$t('hotmart.courses_title')}</h2>
- <span class="subtext">{courses.length === 1 ? $t('hotmart.course_count_one', { count: courses.length }) : $t('hotmart.course_count', { count: courses.length })}</span>
- </div>
-
- <div class="courses-grid">
- {#each paginatedCourses as course (course.id)}
- <CourseCard
- name={course.name}
- price=""
- imageUrl={undefined}
- downloadStatus={getCourseDownloadStatus(Number(course.id) || 0)}
- downloadPercent={getCourseDownloadPercent(Number(course.id) || 0)}
- onDownload={() => downloadCourse(course)}
- />
- {/each}
- </div>
-
- {#if totalPages > 1}
- <div class="pagination">
- <span class="pagination-info">
- {$t('hotmart.page_of', { current: currentPage, total: totalPages })} &middot; {courses.length === 1 ? $t('hotmart.course_count_one', { count: courses.length }) : $t('hotmart.course_count', { count: courses.length })}
- </span>
- <div class="pagination-controls">
- <button
- class="button pagination-btn"
- disabled={currentPage <= 1}
- onclick={() => goToPage(currentPage - 1)}
- >
- &lt;
- </button>
-
- {#each pageNumbers() as page}
- {#if page === -1}
- <span class="pagination-ellipsis">&hellip;</span>
- {:else}
- <button
- class="button pagination-btn"
- class:active={page === currentPage}
- onclick={() => goToPage(page)}
- >
- {page}
- </button>
- {/if}
- {/each}
-
- <button
- class="button pagination-btn"
- disabled={currentPage >= totalPages}
- onclick={() => goToPage(currentPage + 1)}
- >
- &gt;
- </button>
- </div>
- </div>
- {/if}
- {/if}
- </div>
-{:else}
- <div class="page-center">
- <div class="login-card">
- <h2>Data Science Academy</h2>
-
- <div class="form">
- <label class="field">
- <span class="field-label">Cookies JSON</span>
- <textarea
- class="input token-textarea"
- placeholder="Paste cookies JSON from browser extension or a raw token"
- bind:value={token}
- disabled={loading}
- rows="5"
- ></textarea>
- </label>
-
- <input
- type="file"
- accept=".json,.txt"
- class="hidden-file-input"
- bind:this={fileInput}
- onchange={onFileSelected}
- />
- <button class="button" onclick={() => fileInput?.click()} disabled={loading}>
- Import .json file
- </button>
-
- {#if error}
- <p class="error-msg">{error}</p>
- {/if}
-
- <button class="button" onclick={handleTokenLogin} disabled={loading || !token.trim()}>
- {#if loading}
- {$t('hotmart.authenticating')}
- {:else}
- {$t('hotmart.login')}
- {/if}
- </button>
- </div>
- </div>
- </div>
-{/if}
-
-<style>
- .back-link {
- display: inline-flex;
- align-items: center;
- gap: 6px;
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- margin-bottom: var(--padding);
- }
-
- @media (hover: hover) {
- .back-link:hover {
- color: var(--secondary);
- }
- }
-
- .page-center {
- display: flex;
- flex-direction: column;
- align-items: center;
- justify-content: center;
- min-height: calc(100vh - var(--padding) * 4 - 40px);
- gap: var(--padding);
- }
-
- .page-logged {
- display: flex;
- flex-direction: column;
- align-items: center;
- gap: calc(var(--padding) * 1.5);
- padding: calc(var(--padding) * 1.5);
- width: 100%;
- }
-
- .page-logged > :global(*) {
- width: 100%;
- max-width: 1200px;
- }
-
- .session-bar {
- display: flex;
- align-items: center;
- justify-content: space-between;
- }
-
- .session-info {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .session-actions {
- display: flex;
- gap: calc(var(--padding) / 2);
- }
-
- .session-bar :global(.button) {
- padding: calc(var(--padding) / 2) var(--padding);
- font-size: 12.5px;
- }
-
- .spinning {
- animation: spin 0.6s linear infinite;
- }
-
- .courses-header {
- display: flex;
- align-items: baseline;
- gap: var(--padding);
- }
-
- .courses-header h2 {
- margin-block: 0;
- }
-
- .subtext {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .courses-grid {
- display: grid;
- grid-template-columns: repeat(4, 1fr);
- gap: var(--padding);
- }
-
- @media (max-width: 1000px) {
- .courses-grid {
- grid-template-columns: repeat(3, 1fr);
- }
- }
-
- @media (max-width: 750px) {
- .courses-grid {
- grid-template-columns: repeat(2, 1fr);
- }
- }
-
- @media (max-width: 535px) {
- .courses-grid {
- grid-template-columns: 1fr;
- }
- }
-
- .pagination {
- display: flex;
- flex-direction: column;
- align-items: center;
- gap: var(--padding);
- padding-top: var(--padding);
- }
-
- .pagination-info {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .pagination-controls {
- display: flex;
- align-items: center;
- gap: calc(var(--padding) / 3);
- }
-
- .pagination-btn {
- min-width: 36px;
- height: 36px;
- padding: 0;
- display: flex;
- align-items: center;
- justify-content: center;
- font-size: 14.5px;
- }
-
- .pagination-ellipsis {
- min-width: 36px;
- text-align: center;
- color: var(--gray);
- font-size: 14.5px;
- }
-
- .login-card {
- width: 100%;
- max-width: 400px;
- background: var(--button-elevated);
- border-radius: var(--border-radius);
- padding: calc(var(--padding) * 2);
- display: flex;
- flex-direction: column;
- gap: calc(var(--padding) * 1.5);
- }
-
- .login-card h2 {
- margin-block: 0;
- }
-
- .hidden-file-input {
- display: none;
- }
-
- .token-textarea {
- resize: vertical;
- min-height: 80px;
- font-size: 11.5px;
- font-family: var(--font-mono);
- line-height: 1.5;
- }
-
- .form {
- display: flex;
- flex-direction: column;
- gap: var(--padding);
- }
-
- .field {
- display: flex;
- flex-direction: column;
- gap: calc(var(--padding) / 2);
- }
-
- .field-label {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .input {
- width: 100%;
- padding: var(--padding);
- font-size: 14.5px;
- background: var(--button);
- border-radius: var(--border-radius);
- color: var(--secondary);
- border: 1px solid var(--input-border);
- }
-
- .input::placeholder {
- color: var(--gray);
- }
-
- .input:focus-visible {
- border-color: var(--secondary);
- outline: none;
- }
-
- .input:disabled {
- opacity: 0.5;
- cursor: default;
- }
-
- .error-msg {
- color: var(--red);
- font-size: 12.5px;
- font-weight: 500;
- }
-
- .spinner-section {
- display: flex;
- flex-direction: column;
- align-items: center;
- gap: var(--padding);
- padding: calc(var(--padding) * 4) 0;
- }
-
- .spinner {
- width: 24px;
- height: 24px;
- border: 2px solid var(--input-border);
- border-top-color: var(--blue);
- border-radius: 50%;
- animation: spin 0.6s linear infinite;
- }
-
- @keyframes spin {
- to {
- transform: rotate(360deg);
- }
- }
-
- .spinner-text {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .error-section {
- display: flex;
- flex-direction: column;
- align-items: center;
- gap: var(--padding);
- padding: calc(var(--padding) * 2) 0;
- }
-
- .empty-text {
- color: var(--gray);
- font-size: 14.5px;
- text-align: center;
- padding: calc(var(--padding) * 4) 0;
- }
-</style>
diff --git a/src/routes/courses/eduzznutror/+page.svelte b/src/routes/courses/eduzznutror/+page.svelte
deleted file mode 100644
index 07d3fce4..00000000
--- a/src/routes/courses/eduzznutror/+page.svelte
+++ /dev/null
@@ -1,621 +0,0 @@
-<script lang="ts">
- import { pluginInvoke } from "$lib/plugin-invoke";
- import { open } from "@tauri-apps/plugin-dialog";
- import CourseCard from "$components/hotmart/CourseCard.svelte";
- import { showToast } from "$lib/stores/toast-store.svelte";
- import { getDownloads } from "$lib/stores/download-store.svelte";
- import { getSettings } from "$lib/stores/settings-store.svelte";
- import { t } from "$lib/i18n";
-
- let downloads = $derived(getDownloads());
-
- type NutrorCourse = {
- id: string;
- name: string;
- hash: string;
- };
-
- let token = $state("");
- let refreshToken = $state("");
- let loading = $state(false);
- let error = $state("");
-
- let fileInput: HTMLInputElement = $state() as HTMLInputElement;
-
- function onFileSelected(e: Event) {
- const input = e.target as HTMLInputElement;
- const file = input.files?.[0];
- if (!file) return;
- const reader = new FileReader();
- reader.onload = () => { token = reader.result as string; };
- reader.readAsText(file);
- input.value = "";
- }
-
- let checking = $state(true);
- let loggedIn = $state(false);
- let sessionEmail = $state("");
-
- let courses: NutrorCourse[] = $state([]);
- let loadingCourses = $state(false);
- let coursesError = $state("");
-
- const ITEMS_PER_PAGE = 12;
- let currentPage = $state(1);
-
- let totalPages = $derived(Math.max(1, Math.ceil(courses.length / ITEMS_PER_PAGE)));
- let paginatedCourses = $derived(
- courses.slice((currentPage - 1) * ITEMS_PER_PAGE, currentPage * ITEMS_PER_PAGE)
- );
-
- let pageNumbers = $derived((): number[] => {
- const pages: number[] = [];
- if (totalPages <= 7) {
- for (let i = 1; i <= totalPages; i++) pages.push(i);
- } else {
- pages.push(1);
- if (currentPage > 3) pages.push(-1);
- const start = Math.max(2, currentPage - 1);
- const end = Math.min(totalPages - 1, currentPage + 1);
- for (let i = start; i <= end; i++) pages.push(i);
- if (currentPage < totalPages - 2) pages.push(-1);
- pages.push(totalPages);
- }
- return pages;
- });
-
- function goToPage(page: number) {
- if (page >= 1 && page <= totalPages) {
- currentPage = page;
- }
- }
-
- $effect(() => {
- checkSession();
- });
-
- async function checkSession() {
- try {
- const result = await pluginInvoke<string>("courses", "nutror_check_session");
- sessionEmail = result;
- loggedIn = true;
- loadCourses();
- } catch {
- loggedIn = false;
- } finally {
- checking = false;
- }
- }
-
- async function handleTokenLogin() {
- if (!token.trim()) return;
- error = "";
- loading = true;
- try {
- const result = await pluginInvoke<string>("courses", "nutror_login_token", {
- token: token.trim(),
- refreshToken: refreshToken.trim() || null,
- });
- sessionEmail = result || "Token";
- loggedIn = true;
- loadCourses();
- } catch (e: any) {
- error = typeof e === "string" ? e : e.message ?? $t('hotmart.unknown_error');
- } finally {
- loading = false;
- }
- }
-
- async function handleLogout() {
- try {
- await pluginInvoke("courses", "nutror_logout");
- } catch {
- }
- loggedIn = false;
- sessionEmail = "";
- courses = [];
- coursesError = "";
- currentPage = 1;
- }
-
- async function loadCourses() {
- loadingCourses = true;
- coursesError = "";
- try {
- courses = await pluginInvoke("courses", "nutror_list_courses");
- currentPage = 1;
- } catch (e: any) {
- coursesError = typeof e === "string" ? e : e.message ?? $t('hotmart.courses_error');
- } finally {
- loadingCourses = false;
- }
- }
-
- function getCourseDownloadStatus(courseId: string): "idle" | "downloading" | "complete" | "error" {
- const numId = Number(courseId) || 0;
- const item = downloads.get(numId);
- if (!item) return "idle";
- const s = item.status;
- if (s === "queued" || s === "paused" || s === "seeding") return "downloading";
- return s;
- }
-
- function getCourseDownloadPercent(courseId: string): number {
- const numId = Number(courseId) || 0;
- return downloads.get(numId)?.percent ?? 0;
- }
-
- async function downloadCourse(course: NutrorCourse) {
- const status = getCourseDownloadStatus(course.id);
- if (status === "downloading") {
- showToast("info", $t("toast.download_already_active"));
- return;
- }
- if (status === "complete") return;
-
- const appSettings = getSettings();
- let outputDir: string | null = null;
-
- if (appSettings?.download.always_ask_path) {
- outputDir = await open({ directory: true, title: $t("hotmart.choose_folder") }) as string | null;
- if (!outputDir) return;
- } else {
- outputDir = appSettings?.download.default_output_dir ?? null;
- if (!outputDir) {
- outputDir = await open({ directory: true, title: $t("hotmart.choose_folder") }) as string | null;
- if (!outputDir) return;
- }
- }
-
- try {
- await pluginInvoke("courses", "start_nutror_download", {
- courseJson: JSON.stringify(course),
- outputDir,
- });
- showToast("info", $t("toast.download_preparing"));
- } catch (e: any) {
- const msg = typeof e === "string" ? e : e.message ?? $t("common.error");
- showToast("error", msg);
- }
- }
-
- let refreshing = $state(false);
-
- async function refreshCourses() {
- refreshing = true;
- loadingCourses = true;
- coursesError = "";
- try {
- courses = await pluginInvoke("courses", "nutror_refresh_courses");
- currentPage = 1;
- } catch (e: any) {
- coursesError = typeof e === "string" ? e : e.message ?? $t('hotmart.courses_error');
- } finally {
- loadingCourses = false;
- refreshing = false;
- }
- }
-</script>
-
-<a href="/courses" class="back-link">
- <svg viewBox="0 0 24 24" width="16" height="16" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
- <path d="M19 12H5" />
- <path d="M12 19l-7-7 7-7" />
- </svg>
- {$t("courses.back")}
-</a>
-
-{#if checking}
- <div class="page-center">
- <span class="spinner"></span>
- <span class="spinner-text">{$t('hotmart.checking_session')}</span>
- </div>
-{:else if loggedIn}
- <div class="page-logged">
- <div class="session-bar">
- <span class="session-info">
- {$t('hotmart.logged_as', { email: sessionEmail || "—" })}
- </span>
- <div class="session-actions">
- <button
- class="button"
- onclick={refreshCourses}
- disabled={refreshing}
- aria-label={$t('hotmart.refresh')}
- >
- <svg viewBox="0 0 24 24" width="14" height="14" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class:spinning={refreshing}>
- <path d="M21 2v6h-6" />
- <path d="M3 12a9 9 0 0115-6.7L21 8" />
- <path d="M3 22v-6h6" />
- <path d="M21 12a9 9 0 01-15 6.7L3 16" />
- </svg>
- </button>
- <button class="button" onclick={handleLogout}>{$t('hotmart.logout')}</button>
- </div>
- </div>
-
- {#if loadingCourses}
- <div class="spinner-section">
- <span class="spinner"></span>
- <span class="spinner-text">{$t('hotmart.loading_courses')}</span>
- </div>
- {:else if coursesError}
- <div class="error-section">
- <p class="error-msg">{coursesError}</p>
- <button class="button" onclick={loadCourses}>{$t('common.retry')}</button>
- </div>
- {:else if courses.length === 0}
- <p class="empty-text">{$t('hotmart.no_courses')}</p>
- {:else}
- <div class="courses-header">
- <h2>{$t('hotmart.courses_title')}</h2>
- <span class="subtext">{courses.length === 1 ? $t('hotmart.course_count_one', { count: courses.length }) : $t('hotmart.course_count', { count: courses.length })}</span>
- </div>
-
- <div class="courses-grid">
- {#each paginatedCourses as course (course.id)}
- <CourseCard
- name={course.name}
- price=""
- downloadStatus={getCourseDownloadStatus(course.id)}
- downloadPercent={getCourseDownloadPercent(course.id)}
- onDownload={() => downloadCourse(course)}
- />
- {/each}
- </div>
-
- {#if totalPages > 1}
- <div class="pagination">
- <span class="pagination-info">
- {$t('hotmart.page_of', { current: currentPage, total: totalPages })} &middot; {courses.length === 1 ? $t('hotmart.course_count_one', { count: courses.length }) : $t('hotmart.course_count', { count: courses.length })}
- </span>
- <div class="pagination-controls">
- <button
- class="button pagination-btn"
- disabled={currentPage <= 1}
- onclick={() => goToPage(currentPage - 1)}
- >
- &lt;
- </button>
-
- {#each pageNumbers() as page}
- {#if page === -1}
- <span class="pagination-ellipsis">&hellip;</span>
- {:else}
- <button
- class="button pagination-btn"
- class:active={page === currentPage}
- onclick={() => goToPage(page)}
- >
- {page}
- </button>
- {/if}
- {/each}
-
- <button
- class="button pagination-btn"
- disabled={currentPage >= totalPages}
- onclick={() => goToPage(currentPage + 1)}
- >
- &gt;
- </button>
- </div>
- </div>
- {/if}
- {/if}
- </div>
-{:else}
- <div class="page-center">
- <div class="login-card">
- <h2>Eduzz / Nutror</h2>
-
- <div class="form">
- <label class="field">
- <span class="field-label">Cookies JSON</span>
- <textarea
- class="input token-textarea"
- placeholder="Paste cookies JSON from browser extension or a raw token"
- bind:value={token}
- disabled={loading}
- rows="5"
- ></textarea>
- </label>
-
- <input
- type="file"
- accept=".json,.txt"
- class="hidden-file-input"
- bind:this={fileInput}
- onchange={onFileSelected}
- />
- <button class="button" onclick={() => fileInput?.click()} disabled={loading}>
- Import .json file
- </button>
-
- <label class="field">
- <span class="field-label">Refresh Token (optional)</span>
- <input
- type="text"
- placeholder="Paste your refresh token here..."
- bind:value={refreshToken}
- class="input"
- disabled={loading}
- />
- </label>
-
- {#if error}
- <p class="error-msg">{error}</p>
- {/if}
-
- <button class="button" onclick={handleTokenLogin} disabled={loading || !token.trim()}>
- {#if loading}
- {$t('hotmart.authenticating')}
- {:else}
- {$t('hotmart.login')}
- {/if}
- </button>
- </div>
- </div>
- </div>
-{/if}
-
-<style>
- .back-link {
- display: inline-flex;
- align-items: center;
- gap: 6px;
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- margin-bottom: var(--padding);
- }
-
- @media (hover: hover) {
- .back-link:hover {
- color: var(--secondary);
- }
- }
-
- .page-center {
- display: flex;
- flex-direction: column;
- align-items: center;
- justify-content: center;
- min-height: calc(100vh - var(--padding) * 4 - 40px);
- gap: var(--padding);
- }
-
- .page-logged {
- display: flex;
- flex-direction: column;
- align-items: center;
- gap: calc(var(--padding) * 1.5);
- padding: calc(var(--padding) * 1.5);
- width: 100%;
- }
-
- .page-logged > :global(*) {
- width: 100%;
- max-width: 1200px;
- }
-
- .session-bar {
- display: flex;
- align-items: center;
- justify-content: space-between;
- }
-
- .session-info {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .session-actions {
- display: flex;
- gap: calc(var(--padding) / 2);
- }
-
- .session-bar :global(.button) {
- padding: calc(var(--padding) / 2) var(--padding);
- font-size: 12.5px;
- }
-
- .spinning {
- animation: spin 0.6s linear infinite;
- }
-
- .courses-header {
- display: flex;
- align-items: baseline;
- gap: var(--padding);
- }
-
- .courses-header h2 {
- margin-block: 0;
- }
-
- .subtext {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .courses-grid {
- display: grid;
- grid-template-columns: repeat(4, 1fr);
- gap: var(--padding);
- }
-
- @media (max-width: 1000px) {
- .courses-grid {
- grid-template-columns: repeat(3, 1fr);
- }
- }
-
- @media (max-width: 750px) {
- .courses-grid {
- grid-template-columns: repeat(2, 1fr);
- }
- }
-
- @media (max-width: 535px) {
- .courses-grid {
- grid-template-columns: 1fr;
- }
- }
-
- .pagination {
- display: flex;
- flex-direction: column;
- align-items: center;
- gap: var(--padding);
- padding-top: var(--padding);
- }
-
- .pagination-info {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .pagination-controls {
- display: flex;
- align-items: center;
- gap: calc(var(--padding) / 3);
- }
-
- .pagination-btn {
- min-width: 36px;
- height: 36px;
- padding: 0;
- display: flex;
- align-items: center;
- justify-content: center;
- font-size: 14.5px;
- }
-
- .pagination-ellipsis {
- min-width: 36px;
- text-align: center;
- color: var(--gray);
- font-size: 14.5px;
- }
-
- .login-card {
- width: 100%;
- max-width: 400px;
- background: var(--button-elevated);
- border-radius: var(--border-radius);
- padding: calc(var(--padding) * 2);
- display: flex;
- flex-direction: column;
- gap: calc(var(--padding) * 1.5);
- }
-
- .login-card h2 {
- margin-block: 0;
- }
-
- .hidden-file-input { display: none; }
-
- .token-textarea {
- resize: vertical;
- min-height: 80px;
- font-size: 11.5px;
- font-family: var(--font-mono);
- line-height: 1.5;
- }
-
- .form {
- display: flex;
- flex-direction: column;
- gap: var(--padding);
- }
-
- .field {
- display: flex;
- flex-direction: column;
- gap: calc(var(--padding) / 2);
- }
-
- .field-label {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .input {
- width: 100%;
- padding: var(--padding);
- font-size: 14.5px;
- background: var(--button);
- border-radius: var(--border-radius);
- color: var(--secondary);
- border: 1px solid var(--input-border);
- }
-
- .input::placeholder {
- color: var(--gray);
- }
-
- .input:focus-visible {
- border-color: var(--secondary);
- outline: none;
- }
-
- .input:disabled {
- opacity: 0.5;
- cursor: default;
- }
-
- .error-msg {
- color: var(--red);
- font-size: 12.5px;
- font-weight: 500;
- }
-
- .spinner-section {
- display: flex;
- flex-direction: column;
- align-items: center;
- gap: var(--padding);
- padding: calc(var(--padding) * 4) 0;
- }
-
- .spinner {
- width: 24px;
- height: 24px;
- border: 2px solid var(--input-border);
- border-top-color: var(--blue);
- border-radius: 50%;
- animation: spin 0.6s linear infinite;
- }
-
- @keyframes spin {
- to {
- transform: rotate(360deg);
- }
- }
-
- .spinner-text {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .error-section {
- display: flex;
- flex-direction: column;
- align-items: center;
- gap: var(--padding);
- padding: calc(var(--padding) * 2) 0;
- }
-
- .empty-text {
- color: var(--gray);
- font-size: 14.5px;
- text-align: center;
- padding: calc(var(--padding) * 4) 0;
- }
-</style>
diff --git a/src/routes/courses/entregadigital/+page.svelte b/src/routes/courses/entregadigital/+page.svelte
deleted file mode 100644
index 6777c5b2..00000000
--- a/src/routes/courses/entregadigital/+page.svelte
+++ /dev/null
@@ -1,656 +0,0 @@
-<script lang="ts">
- import { pluginInvoke } from "$lib/plugin-invoke";
- import { open } from "@tauri-apps/plugin-dialog";
- import CourseCard from "$components/hotmart/CourseCard.svelte";
- import { showToast } from "$lib/stores/toast-store.svelte";
- import { getDownloads } from "$lib/stores/download-store.svelte";
- import { getSettings } from "$lib/stores/settings-store.svelte";
- import { t } from "$lib/i18n";
-
- let downloads = $derived(getDownloads());
-
- type EntregaDigitalCourse = {
- id: number;
- name: string;
- };
-
- let token = $state("");
- let siteUrl = $state("");
- let appVersion = $state("");
- let deviceId = $state("");
- let osValue = $state("Web");
- let loading = $state(false);
- let error = $state("");
-
- let fileInput: HTMLInputElement = $state() as HTMLInputElement;
-
- function onFileSelected(e: Event) {
- const input = e.target as HTMLInputElement;
- const file = input.files?.[0];
- if (!file) return;
- const reader = new FileReader();
- reader.onload = () => { token = reader.result as string; };
- reader.readAsText(file);
- input.value = "";
- }
-
- let checking = $state(true);
- let loggedIn = $state(false);
- let sessionEmail = $state("");
-
- let courses: EntregaDigitalCourse[] = $state([]);
- let loadingCourses = $state(false);
- let coursesError = $state("");
-
- const ITEMS_PER_PAGE = 12;
- let currentPage = $state(1);
-
- let totalPages = $derived(Math.max(1, Math.ceil(courses.length / ITEMS_PER_PAGE)));
- let paginatedCourses = $derived(
- courses.slice((currentPage - 1) * ITEMS_PER_PAGE, currentPage * ITEMS_PER_PAGE)
- );
-
- let pageNumbers = $derived((): number[] => {
- const pages: number[] = [];
- if (totalPages <= 7) {
- for (let i = 1; i <= totalPages; i++) pages.push(i);
- } else {
- pages.push(1);
- if (currentPage > 3) pages.push(-1);
- const start = Math.max(2, currentPage - 1);
- const end = Math.min(totalPages - 1, currentPage + 1);
- for (let i = start; i <= end; i++) pages.push(i);
- if (currentPage < totalPages - 2) pages.push(-1);
- pages.push(totalPages);
- }
- return pages;
- });
-
- function goToPage(page: number) {
- if (page >= 1 && page <= totalPages) {
- currentPage = page;
- }
- }
-
- $effect(() => {
- checkSession();
- });
-
- async function checkSession() {
- try {
- const result = await pluginInvoke<string>("courses", "entregadigital_check_session");
- sessionEmail = result;
- loggedIn = true;
- loadCourses();
- } catch {
- loggedIn = false;
- } finally {
- checking = false;
- }
- }
-
- async function handleTokenLogin() {
- if (!token.trim()) return;
- error = "";
- loading = true;
- try {
- const result = await pluginInvoke<string>("courses", "entregadigital_login_token", {
- token: token.trim(),
- siteUrl: siteUrl.trim(),
- appVersion: appVersion.trim(),
- deviceId: deviceId.trim(),
- osValue: osValue.trim(),
- });
- sessionEmail = result || "Token";
- loggedIn = true;
- loadCourses();
- } catch (e: any) {
- error = typeof e === "string" ? e : e.message ?? $t('hotmart.unknown_error');
- } finally {
- loading = false;
- }
- }
-
- async function handleLogout() {
- try {
- await pluginInvoke("courses", "entregadigital_logout");
- } catch {
- }
- loggedIn = false;
- sessionEmail = "";
- courses = [];
- coursesError = "";
- currentPage = 1;
- }
-
- async function loadCourses() {
- loadingCourses = true;
- coursesError = "";
- try {
- courses = await pluginInvoke("courses", "entregadigital_list_courses");
- currentPage = 1;
- } catch (e: any) {
- coursesError = typeof e === "string" ? e : e.message ?? $t('hotmart.courses_error');
- } finally {
- loadingCourses = false;
- }
- }
-
- function getCourseDownloadStatus(courseId: number): "idle" | "downloading" | "complete" | "error" {
- const item = downloads.get(courseId);
- if (!item) return "idle";
- const s = item.status;
- if (s === "queued" || s === "paused" || s === "seeding") return "downloading";
- return s;
- }
-
- function getCourseDownloadPercent(courseId: number): number {
- return downloads.get(courseId)?.percent ?? 0;
- }
-
- async function downloadCourse(course: EntregaDigitalCourse) {
- const status = getCourseDownloadStatus(course.id);
- if (status === "downloading") {
- showToast("info", $t("toast.download_already_active"));
- return;
- }
- if (status === "complete") return;
-
- const appSettings = getSettings();
- let outputDir: string | null = null;
-
- if (appSettings?.download.always_ask_path) {
- outputDir = await open({ directory: true, title: $t("hotmart.choose_folder") }) as string | null;
- if (!outputDir) return;
- } else {
- outputDir = appSettings?.download.default_output_dir ?? null;
- if (!outputDir) {
- outputDir = await open({ directory: true, title: $t("hotmart.choose_folder") }) as string | null;
- if (!outputDir) return;
- }
- }
-
- try {
- await pluginInvoke("courses", "start_entregadigital_course_download", {
- courseJson: JSON.stringify(course),
- outputDir,
- });
- showToast("info", $t("toast.download_preparing"));
- } catch (e: any) {
- const msg = typeof e === "string" ? e : e.message ?? $t("common.error");
- showToast("error", msg);
- }
- }
-
- let refreshing = $state(false);
-
- async function refreshCourses() {
- refreshing = true;
- loadingCourses = true;
- coursesError = "";
- try {
- courses = await pluginInvoke("courses", "entregadigital_refresh_courses");
- currentPage = 1;
- } catch (e: any) {
- coursesError = typeof e === "string" ? e : e.message ?? $t('hotmart.courses_error');
- } finally {
- loadingCourses = false;
- refreshing = false;
- }
- }
-</script>
-
-<a href="/courses" class="back-link">
- <svg viewBox="0 0 24 24" width="16" height="16" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
- <path d="M19 12H5" />
- <path d="M12 19l-7-7 7-7" />
- </svg>
- {$t("courses.back")}
-</a>
-
-{#if checking}
- <div class="page-center">
- <span class="spinner"></span>
- <span class="spinner-text">{$t('hotmart.checking_session')}</span>
- </div>
-{:else if loggedIn}
- <div class="page-logged">
- <div class="session-bar">
- <span class="session-info">
- {$t('hotmart.logged_as', { email: sessionEmail || "—" })}
- </span>
- <div class="session-actions">
- <button
- class="button"
- onclick={refreshCourses}
- disabled={refreshing}
- aria-label={$t('hotmart.refresh')}
- >
- <svg viewBox="0 0 24 24" width="14" height="14" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class:spinning={refreshing}>
- <path d="M21 2v6h-6" />
- <path d="M3 12a9 9 0 0115-6.7L21 8" />
- <path d="M3 22v-6h6" />
- <path d="M21 12a9 9 0 01-15 6.7L3 16" />
- </svg>
- </button>
- <button class="button" onclick={handleLogout}>{$t('hotmart.logout')}</button>
- </div>
- </div>
-
- {#if loadingCourses}
- <div class="spinner-section">
- <span class="spinner"></span>
- <span class="spinner-text">{$t('hotmart.loading_courses')}</span>
- </div>
- {:else if coursesError}
- <div class="error-section">
- <p class="error-msg">{coursesError}</p>
- <button class="button" onclick={loadCourses}>{$t('common.retry')}</button>
- </div>
- {:else if courses.length === 0}
- <p class="empty-text">{$t('hotmart.no_courses')}</p>
- {:else}
- <div class="courses-header">
- <h2>{$t('hotmart.courses_title')}</h2>
- <span class="subtext">{courses.length === 1 ? $t('hotmart.course_count_one', { count: courses.length }) : $t('hotmart.course_count', { count: courses.length })}</span>
- </div>
-
- <div class="courses-grid">
- {#each paginatedCourses as course (course.id)}
- <CourseCard
- name={course.name}
- price={""}
- downloadStatus={getCourseDownloadStatus(course.id)}
- downloadPercent={getCourseDownloadPercent(course.id)}
- onDownload={() => downloadCourse(course)}
- />
- {/each}
- </div>
-
- {#if totalPages > 1}
- <div class="pagination">
- <span class="pagination-info">
- {$t('hotmart.page_of', { current: currentPage, total: totalPages })} &middot; {courses.length === 1 ? $t('hotmart.course_count_one', { count: courses.length }) : $t('hotmart.course_count', { count: courses.length })}
- </span>
- <div class="pagination-controls">
- <button
- class="button pagination-btn"
- disabled={currentPage <= 1}
- onclick={() => goToPage(currentPage - 1)}
- >
- &lt;
- </button>
-
- {#each pageNumbers() as page}
- {#if page === -1}
- <span class="pagination-ellipsis">&hellip;</span>
- {:else}
- <button
- class="button pagination-btn"
- class:active={page === currentPage}
- onclick={() => goToPage(page)}
- >
- {page}
- </button>
- {/if}
- {/each}
-
- <button
- class="button pagination-btn"
- disabled={currentPage >= totalPages}
- onclick={() => goToPage(currentPage + 1)}
- >
- &gt;
- </button>
- </div>
- </div>
- {/if}
- {/if}
- </div>
-{:else}
- <div class="page-center">
- <div class="login-card">
- <h2>Entrega Digital</h2>
-
- <div class="form">
- <label class="field">
- <span class="field-label">Platform URL</span>
- <input
- type="url"
- placeholder="https://exemplo.entregadigital.app.br"
- bind:value={siteUrl}
- class="input"
- disabled={loading}
- />
- </label>
- <label class="field">
- <span class="field-label">Cookies JSON</span>
- <textarea
- class="input token-textarea"
- placeholder="Paste cookies JSON from browser extension or a raw token"
- bind:value={token}
- disabled={loading}
- rows="5"
- ></textarea>
- </label>
-
- <input
- type="file"
- accept=".json,.txt"
- class="hidden-file-input"
- bind:this={fileInput}
- onchange={onFileSelected}
- />
- <button class="button" onclick={() => fileInput?.click()} disabled={loading}>
- Import .json file
- </button>
-
- <label class="field">
- <span class="field-label">App Version</span>
- <input
- type="text"
- placeholder="e.g. 1.2.3"
- bind:value={appVersion}
- class="input"
- disabled={loading}
- />
- </label>
- <label class="field">
- <span class="field-label">Device ID</span>
- <input
- type="text"
- placeholder="from network tab"
- bind:value={deviceId}
- class="input"
- disabled={loading}
- />
- </label>
- <label class="field">
- <span class="field-label">OS</span>
- <input
- type="text"
- placeholder="Web"
- bind:value={osValue}
- class="input"
- disabled={loading}
- />
- </label>
-
- {#if error}
- <p class="error-msg">{error}</p>
- {/if}
-
- <button class="button" onclick={handleTokenLogin} disabled={loading || !token.trim()}>
- {#if loading}
- {$t('hotmart.authenticating')}
- {:else}
- {$t('hotmart.login')}
- {/if}
- </button>
- </div>
- </div>
- </div>
-{/if}
-
-<style>
- .back-link {
- display: inline-flex;
- align-items: center;
- gap: 6px;
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- margin-bottom: var(--padding);
- }
-
- @media (hover: hover) {
- .back-link:hover {
- color: var(--secondary);
- }
- }
-
- .page-center {
- display: flex;
- flex-direction: column;
- align-items: center;
- justify-content: center;
- min-height: calc(100vh - var(--padding) * 4 - 40px);
- gap: var(--padding);
- }
-
- .page-logged {
- display: flex;
- flex-direction: column;
- align-items: center;
- gap: calc(var(--padding) * 1.5);
- padding: calc(var(--padding) * 1.5);
- width: 100%;
- }
-
- .page-logged > :global(*) {
- width: 100%;
- max-width: 1200px;
- }
-
- .session-bar {
- display: flex;
- align-items: center;
- justify-content: space-between;
- }
-
- .session-info {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .session-actions {
- display: flex;
- gap: calc(var(--padding) / 2);
- }
-
- .session-bar :global(.button) {
- padding: calc(var(--padding) / 2) var(--padding);
- font-size: 12.5px;
- }
-
- .spinning {
- animation: spin 0.6s linear infinite;
- }
-
- .courses-header {
- display: flex;
- align-items: baseline;
- gap: var(--padding);
- }
-
- .courses-header h2 {
- margin-block: 0;
- }
-
- .subtext {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .courses-grid {
- display: grid;
- grid-template-columns: repeat(4, 1fr);
- gap: var(--padding);
- }
-
- @media (max-width: 1000px) {
- .courses-grid {
- grid-template-columns: repeat(3, 1fr);
- }
- }
-
- @media (max-width: 750px) {
- .courses-grid {
- grid-template-columns: repeat(2, 1fr);
- }
- }
-
- @media (max-width: 535px) {
- .courses-grid {
- grid-template-columns: 1fr;
- }
- }
-
- .pagination {
- display: flex;
- flex-direction: column;
- align-items: center;
- gap: var(--padding);
- padding-top: var(--padding);
- }
-
- .pagination-info {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .pagination-controls {
- display: flex;
- align-items: center;
- gap: calc(var(--padding) / 3);
- }
-
- .pagination-btn {
- min-width: 36px;
- height: 36px;
- padding: 0;
- display: flex;
- align-items: center;
- justify-content: center;
- font-size: 14.5px;
- }
-
- .pagination-ellipsis {
- min-width: 36px;
- text-align: center;
- color: var(--gray);
- font-size: 14.5px;
- }
-
- .login-card {
- width: 100%;
- max-width: 400px;
- background: var(--button-elevated);
- border-radius: var(--border-radius);
- padding: calc(var(--padding) * 2);
- display: flex;
- flex-direction: column;
- gap: calc(var(--padding) * 1.5);
- }
-
- .login-card h2 {
- margin-block: 0;
- }
-
- .hidden-file-input {
- display: none;
- }
-
- .token-textarea {
- resize: vertical;
- min-height: 80px;
- font-size: 11.5px;
- font-family: var(--font-mono);
- line-height: 1.5;
- }
-
- .form {
- display: flex;
- flex-direction: column;
- gap: var(--padding);
- }
-
- .field {
- display: flex;
- flex-direction: column;
- gap: calc(var(--padding) / 2);
- }
-
- .field-label {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .input {
- width: 100%;
- padding: var(--padding);
- font-size: 14.5px;
- background: var(--button);
- border-radius: var(--border-radius);
- color: var(--secondary);
- border: 1px solid var(--input-border);
- }
-
- .input::placeholder {
- color: var(--gray);
- }
-
- .input:focus-visible {
- border-color: var(--secondary);
- outline: none;
- }
-
- .input:disabled {
- opacity: 0.5;
- cursor: default;
- }
-
- .error-msg {
- color: var(--red);
- font-size: 12.5px;
- font-weight: 500;
- }
-
- .spinner-section {
- display: flex;
- flex-direction: column;
- align-items: center;
- gap: var(--padding);
- padding: calc(var(--padding) * 4) 0;
- }
-
- .spinner {
- width: 24px;
- height: 24px;
- border: 2px solid var(--input-border);
- border-top-color: var(--blue);
- border-radius: 50%;
- animation: spin 0.6s linear infinite;
- }
-
- @keyframes spin {
- to {
- transform: rotate(360deg);
- }
- }
-
- .spinner-text {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .error-section {
- display: flex;
- flex-direction: column;
- align-items: center;
- gap: var(--padding);
- padding: calc(var(--padding) * 2) 0;
- }
-
- .empty-text {
- color: var(--gray);
- font-size: 14.5px;
- text-align: center;
- padding: calc(var(--padding) * 4) 0;
- }
-</style>
diff --git a/src/routes/courses/estrategia-concursos/+page.svelte b/src/routes/courses/estrategia-concursos/+page.svelte
deleted file mode 100644
index 124f2e32..00000000
--- a/src/routes/courses/estrategia-concursos/+page.svelte
+++ /dev/null
@@ -1,604 +0,0 @@
-<script lang="ts">
- import { pluginInvoke } from "$lib/plugin-invoke";
- import { open } from "@tauri-apps/plugin-dialog";
- import CourseCard from "$components/hotmart/CourseCard.svelte";
- import { showToast } from "$lib/stores/toast-store.svelte";
- import { getDownloads } from "$lib/stores/download-store.svelte";
- import { getSettings } from "$lib/stores/settings-store.svelte";
- import { t } from "$lib/i18n";
-
- let downloads = $derived(getDownloads());
-
- type EstrategiaConcursosCourse = {
- id: number;
- name: string;
- total_aulas: number;
- };
-
- let token = $state("");
- let loading = $state(false);
- let error = $state("");
-
- let fileInput: HTMLInputElement = $state() as HTMLInputElement;
-
- function onFileSelected(e: Event) {
- const input = e.target as HTMLInputElement;
- const file = input.files?.[0];
- if (!file) return;
- const reader = new FileReader();
- reader.onload = () => { token = reader.result as string; };
- reader.readAsText(file);
- input.value = "";
- }
-
- let checking = $state(true);
- let loggedIn = $state(false);
- let sessionEmail = $state("");
-
- let courses: EstrategiaConcursosCourse[] = $state([]);
- let loadingCourses = $state(false);
- let coursesError = $state("");
-
- const ITEMS_PER_PAGE = 12;
- let currentPage = $state(1);
-
- let totalPages = $derived(Math.max(1, Math.ceil(courses.length / ITEMS_PER_PAGE)));
- let paginatedCourses = $derived(
- courses.slice((currentPage - 1) * ITEMS_PER_PAGE, currentPage * ITEMS_PER_PAGE)
- );
-
- let pageNumbers = $derived((): number[] => {
- const pages: number[] = [];
- if (totalPages <= 7) {
- for (let i = 1; i <= totalPages; i++) pages.push(i);
- } else {
- pages.push(1);
- if (currentPage > 3) pages.push(-1);
- const start = Math.max(2, currentPage - 1);
- const end = Math.min(totalPages - 1, currentPage + 1);
- for (let i = start; i <= end; i++) pages.push(i);
- if (currentPage < totalPages - 2) pages.push(-1);
- pages.push(totalPages);
- }
- return pages;
- });
-
- function goToPage(page: number) {
- if (page >= 1 && page <= totalPages) {
- currentPage = page;
- }
- }
-
- $effect(() => {
- checkSession();
- });
-
- async function checkSession() {
- try {
- const result = await pluginInvoke<string>("courses", "estrategia_concursos_check_session");
- sessionEmail = result;
- loggedIn = true;
- loadCourses();
- } catch {
- loggedIn = false;
- } finally {
- checking = false;
- }
- }
-
- async function handleTokenLogin() {
- if (!token.trim()) return;
- error = "";
- loading = true;
- try {
- const result = await pluginInvoke<string>("courses", "estrategia_concursos_login_token", { token: token.trim() });
- sessionEmail = result || "Token";
- loggedIn = true;
- loadCourses();
- } catch (e: any) {
- error = typeof e === "string" ? e : e.message ?? $t('hotmart.unknown_error');
- } finally {
- loading = false;
- }
- }
-
- async function handleLogout() {
- try {
- await pluginInvoke("courses", "estrategia_concursos_logout");
- } catch {
- }
- loggedIn = false;
- sessionEmail = "";
- courses = [];
- coursesError = "";
- currentPage = 1;
- }
-
- async function loadCourses() {
- loadingCourses = true;
- coursesError = "";
- try {
- courses = await pluginInvoke("courses", "estrategia_concursos_list_courses");
- currentPage = 1;
- } catch (e: any) {
- coursesError = typeof e === "string" ? e : e.message ?? $t('hotmart.courses_error');
- } finally {
- loadingCourses = false;
- }
- }
-
- function getCourseDownloadStatus(courseId: number): "idle" | "downloading" | "complete" | "error" {
- const item = downloads.get(courseId);
- if (!item) return "idle";
- const s = item.status;
- if (s === "queued" || s === "paused" || s === "seeding") return "downloading";
- return s;
- }
-
- function getCourseDownloadPercent(courseId: number): number {
- return downloads.get(courseId)?.percent ?? 0;
- }
-
- async function downloadCourse(course: EstrategiaConcursosCourse) {
- const status = getCourseDownloadStatus(course.id);
- if (status === "downloading") {
- showToast("info", $t("toast.download_already_active"));
- return;
- }
- if (status === "complete") return;
-
- const appSettings = getSettings();
- let outputDir: string | null = null;
-
- if (appSettings?.download.always_ask_path) {
- outputDir = await open({ directory: true, title: $t("hotmart.choose_folder") }) as string | null;
- if (!outputDir) return;
- } else {
- outputDir = appSettings?.download.default_output_dir ?? null;
- if (!outputDir) {
- outputDir = await open({ directory: true, title: $t("hotmart.choose_folder") }) as string | null;
- if (!outputDir) return;
- }
- }
-
- try {
- await pluginInvoke("courses", "start_estrategia_concursos_download", {
- courseJson: JSON.stringify(course),
- outputDir,
- });
- showToast("info", $t("toast.download_preparing"));
- } catch (e: any) {
- const msg = typeof e === "string" ? e : e.message ?? $t("common.error");
- showToast("error", msg);
- }
- }
-
- let refreshing = $state(false);
-
- async function refreshCourses() {
- refreshing = true;
- loadingCourses = true;
- coursesError = "";
- try {
- courses = await pluginInvoke("courses", "estrategia_concursos_refresh_courses");
- currentPage = 1;
- } catch (e: any) {
- coursesError = typeof e === "string" ? e : e.message ?? $t('hotmart.courses_error');
- } finally {
- loadingCourses = false;
- refreshing = false;
- }
- }
-</script>
-
-<a href="/courses" class="back-link">
- <svg viewBox="0 0 24 24" width="16" height="16" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
- <path d="M19 12H5" />
- <path d="M12 19l-7-7 7-7" />
- </svg>
- {$t("courses.back")}
-</a>
-
-{#if checking}
- <div class="page-center">
- <span class="spinner"></span>
- <span class="spinner-text">{$t('hotmart.checking_session')}</span>
- </div>
-{:else if loggedIn}
- <div class="page-logged">
- <div class="session-bar">
- <span class="session-info">
- {$t('hotmart.logged_as', { email: sessionEmail || "—" })}
- </span>
- <div class="session-actions">
- <button
- class="button"
- onclick={refreshCourses}
- disabled={refreshing}
- aria-label={$t('hotmart.refresh')}
- >
- <svg viewBox="0 0 24 24" width="14" height="14" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class:spinning={refreshing}>
- <path d="M21 2v6h-6" />
- <path d="M3 12a9 9 0 0115-6.7L21 8" />
- <path d="M3 22v-6h6" />
- <path d="M21 12a9 9 0 01-15 6.7L3 16" />
- </svg>
- </button>
- <button class="button" onclick={handleLogout}>{$t('hotmart.logout')}</button>
- </div>
- </div>
-
- {#if loadingCourses}
- <div class="spinner-section">
- <span class="spinner"></span>
- <span class="spinner-text">{$t('hotmart.loading_courses')}</span>
- </div>
- {:else if coursesError}
- <div class="error-section">
- <p class="error-msg">{coursesError}</p>
- <button class="button" onclick={loadCourses}>{$t('common.retry')}</button>
- </div>
- {:else if courses.length === 0}
- <p class="empty-text">{$t('hotmart.no_courses')}</p>
- {:else}
- <div class="courses-header">
- <h2>{$t('hotmart.courses_title')}</h2>
- <span class="subtext">{courses.length === 1 ? $t('hotmart.course_count_one', { count: courses.length }) : $t('hotmart.course_count', { count: courses.length })}</span>
- </div>
-
- <div class="courses-grid">
- {#each paginatedCourses as course (course.id)}
- <CourseCard
- name={course.name}
- price={`${course.total_aulas} aulas`}
- downloadStatus={getCourseDownloadStatus(course.id)}
- downloadPercent={getCourseDownloadPercent(course.id)}
- onDownload={() => downloadCourse(course)}
- />
- {/each}
- </div>
-
- {#if totalPages > 1}
- <div class="pagination">
- <span class="pagination-info">
- {$t('hotmart.page_of', { current: currentPage, total: totalPages })} &middot; {courses.length === 1 ? $t('hotmart.course_count_one', { count: courses.length }) : $t('hotmart.course_count', { count: courses.length })}
- </span>
- <div class="pagination-controls">
- <button
- class="button pagination-btn"
- disabled={currentPage <= 1}
- onclick={() => goToPage(currentPage - 1)}
- >
- &lt;
- </button>
-
- {#each pageNumbers() as page}
- {#if page === -1}
- <span class="pagination-ellipsis">&hellip;</span>
- {:else}
- <button
- class="button pagination-btn"
- class:active={page === currentPage}
- onclick={() => goToPage(page)}
- >
- {page}
- </button>
- {/if}
- {/each}
-
- <button
- class="button pagination-btn"
- disabled={currentPage >= totalPages}
- onclick={() => goToPage(currentPage + 1)}
- >
- &gt;
- </button>
- </div>
- </div>
- {/if}
- {/if}
- </div>
-{:else}
- <div class="page-center">
- <div class="login-card">
- <h2>Estrat&eacute;gia Concursos</h2>
-
- <div class="form">
- <label class="field">
- <span class="field-label">Cookies JSON</span>
- <textarea
- class="input token-textarea"
- placeholder="Paste cookies JSON from browser extension or a raw token"
- bind:value={token}
- disabled={loading}
- rows="5"
- ></textarea>
- </label>
-
- <input
- type="file"
- accept=".json,.txt"
- class="hidden-file-input"
- bind:this={fileInput}
- onchange={onFileSelected}
- />
- <button class="button" onclick={() => fileInput?.click()} disabled={loading}>
- Import .json file
- </button>
-
- {#if error}
- <p class="error-msg">{error}</p>
- {/if}
-
- <button class="button" onclick={handleTokenLogin} disabled={loading || !token.trim()}>
- {#if loading}
- {$t('hotmart.authenticating')}
- {:else}
- {$t('hotmart.login')}
- {/if}
- </button>
- </div>
- </div>
- </div>
-{/if}
-
-<style>
- .back-link {
- display: inline-flex;
- align-items: center;
- gap: 6px;
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- margin-bottom: var(--padding);
- }
-
- @media (hover: hover) {
- .back-link:hover {
- color: var(--secondary);
- }
- }
-
- .page-center {
- display: flex;
- flex-direction: column;
- align-items: center;
- justify-content: center;
- min-height: calc(100vh - var(--padding) * 4 - 40px);
- gap: var(--padding);
- }
-
- .page-logged {
- display: flex;
- flex-direction: column;
- align-items: center;
- gap: calc(var(--padding) * 1.5);
- padding: calc(var(--padding) * 1.5);
- width: 100%;
- }
-
- .page-logged > :global(*) {
- width: 100%;
- max-width: 1200px;
- }
-
- .session-bar {
- display: flex;
- align-items: center;
- justify-content: space-between;
- }
-
- .session-info {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .session-actions {
- display: flex;
- gap: calc(var(--padding) / 2);
- }
-
- .session-bar :global(.button) {
- padding: calc(var(--padding) / 2) var(--padding);
- font-size: 12.5px;
- }
-
- .spinning {
- animation: spin 0.6s linear infinite;
- }
-
- .courses-header {
- display: flex;
- align-items: baseline;
- gap: var(--padding);
- }
-
- .courses-header h2 {
- margin-block: 0;
- }
-
- .subtext {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .courses-grid {
- display: grid;
- grid-template-columns: repeat(4, 1fr);
- gap: var(--padding);
- }
-
- @media (max-width: 1000px) {
- .courses-grid {
- grid-template-columns: repeat(3, 1fr);
- }
- }
-
- @media (max-width: 750px) {
- .courses-grid {
- grid-template-columns: repeat(2, 1fr);
- }
- }
-
- @media (max-width: 535px) {
- .courses-grid {
- grid-template-columns: 1fr;
- }
- }
-
- .pagination {
- display: flex;
- flex-direction: column;
- align-items: center;
- gap: var(--padding);
- padding-top: var(--padding);
- }
-
- .pagination-info {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .pagination-controls {
- display: flex;
- align-items: center;
- gap: calc(var(--padding) / 3);
- }
-
- .pagination-btn {
- min-width: 36px;
- height: 36px;
- padding: 0;
- display: flex;
- align-items: center;
- justify-content: center;
- font-size: 14.5px;
- }
-
- .pagination-ellipsis {
- min-width: 36px;
- text-align: center;
- color: var(--gray);
- font-size: 14.5px;
- }
-
- .login-card {
- width: 100%;
- max-width: 400px;
- background: var(--button-elevated);
- border-radius: var(--border-radius);
- padding: calc(var(--padding) * 2);
- display: flex;
- flex-direction: column;
- gap: calc(var(--padding) * 1.5);
- }
-
- .login-card h2 {
- margin-block: 0;
- }
-
- .hidden-file-input { display: none; }
-
- .token-textarea {
- resize: vertical;
- min-height: 80px;
- font-size: 11.5px;
- font-family: var(--font-mono);
- line-height: 1.5;
- }
-
- .form {
- display: flex;
- flex-direction: column;
- gap: var(--padding);
- }
-
- .field {
- display: flex;
- flex-direction: column;
- gap: calc(var(--padding) / 2);
- }
-
- .field-label {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .input {
- width: 100%;
- padding: var(--padding);
- font-size: 14.5px;
- background: var(--button);
- border-radius: var(--border-radius);
- color: var(--secondary);
- border: 1px solid var(--input-border);
- }
-
- .input::placeholder {
- color: var(--gray);
- }
-
- .input:focus-visible {
- border-color: var(--secondary);
- outline: none;
- }
-
- .input:disabled {
- opacity: 0.5;
- cursor: default;
- }
-
- .error-msg {
- color: var(--red);
- font-size: 12.5px;
- font-weight: 500;
- }
-
- .spinner-section {
- display: flex;
- flex-direction: column;
- align-items: center;
- gap: var(--padding);
- padding: calc(var(--padding) * 4) 0;
- }
-
- .spinner {
- width: 24px;
- height: 24px;
- border: 2px solid var(--input-border);
- border-top-color: var(--blue);
- border-radius: 50%;
- animation: spin 0.6s linear infinite;
- }
-
- @keyframes spin {
- to {
- transform: rotate(360deg);
- }
- }
-
- .spinner-text {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .error-section {
- display: flex;
- flex-direction: column;
- align-items: center;
- gap: var(--padding);
- padding: calc(var(--padding) * 2) 0;
- }
-
- .empty-text {
- color: var(--gray);
- font-size: 14.5px;
- text-align: center;
- padding: calc(var(--padding) * 4) 0;
- }
-</style>
diff --git a/src/routes/courses/estrategia-ldi/+page.svelte b/src/routes/courses/estrategia-ldi/+page.svelte
deleted file mode 100644
index a2dd5f9a..00000000
--- a/src/routes/courses/estrategia-ldi/+page.svelte
+++ /dev/null
@@ -1,603 +0,0 @@
-<script lang="ts">
- import { pluginInvoke } from "$lib/plugin-invoke";
- import { open } from "@tauri-apps/plugin-dialog";
- import CourseCard from "$components/hotmart/CourseCard.svelte";
- import { showToast } from "$lib/stores/toast-store.svelte";
- import { getDownloads } from "$lib/stores/download-store.svelte";
- import { getSettings } from "$lib/stores/settings-store.svelte";
- import { t } from "$lib/i18n";
-
- let downloads = $derived(getDownloads());
-
- type EstrategiaLdiCourse = {
- id: string;
- name: string;
- };
-
- let token = $state("");
- let loading = $state(false);
- let error = $state("");
-
- let fileInput: HTMLInputElement = $state() as HTMLInputElement;
-
- function onFileSelected(e: Event) {
- const input = e.target as HTMLInputElement;
- const file = input.files?.[0];
- if (!file) return;
- const reader = new FileReader();
- reader.onload = () => { token = reader.result as string; };
- reader.readAsText(file);
- input.value = "";
- }
-
- let checking = $state(true);
- let loggedIn = $state(false);
- let sessionEmail = $state("");
-
- let courses: EstrategiaLdiCourse[] = $state([]);
- let loadingCourses = $state(false);
- let coursesError = $state("");
-
- const ITEMS_PER_PAGE = 12;
- let currentPage = $state(1);
-
- let totalPages = $derived(Math.max(1, Math.ceil(courses.length / ITEMS_PER_PAGE)));
- let paginatedCourses = $derived(
- courses.slice((currentPage - 1) * ITEMS_PER_PAGE, currentPage * ITEMS_PER_PAGE)
- );
-
- let pageNumbers = $derived((): number[] => {
- const pages: number[] = [];
- if (totalPages <= 7) {
- for (let i = 1; i <= totalPages; i++) pages.push(i);
- } else {
- pages.push(1);
- if (currentPage > 3) pages.push(-1);
- const start = Math.max(2, currentPage - 1);
- const end = Math.min(totalPages - 1, currentPage + 1);
- for (let i = start; i <= end; i++) pages.push(i);
- if (currentPage < totalPages - 2) pages.push(-1);
- pages.push(totalPages);
- }
- return pages;
- });
-
- function goToPage(page: number) {
- if (page >= 1 && page <= totalPages) {
- currentPage = page;
- }
- }
-
- $effect(() => {
- checkSession();
- });
-
- async function checkSession() {
- try {
- const result = await pluginInvoke<string>("courses", "estrategia_ldi_check_session");
- sessionEmail = result;
- loggedIn = true;
- loadCourses();
- } catch {
- loggedIn = false;
- } finally {
- checking = false;
- }
- }
-
- async function handleTokenLogin() {
- if (!token.trim()) return;
- error = "";
- loading = true;
- try {
- const result = await pluginInvoke<string>("courses", "estrategia_ldi_login_token", { token: token.trim() });
- sessionEmail = result || "Token";
- loggedIn = true;
- loadCourses();
- } catch (e: any) {
- error = typeof e === "string" ? e : e.message ?? $t('hotmart.unknown_error');
- } finally {
- loading = false;
- }
- }
-
- async function handleLogout() {
- try {
- await pluginInvoke("courses", "estrategia_ldi_logout");
- } catch {
- }
- loggedIn = false;
- sessionEmail = "";
- courses = [];
- coursesError = "";
- currentPage = 1;
- }
-
- async function loadCourses() {
- loadingCourses = true;
- coursesError = "";
- try {
- courses = await pluginInvoke("courses", "estrategia_ldi_list_courses");
- currentPage = 1;
- } catch (e: any) {
- coursesError = typeof e === "string" ? e : e.message ?? $t('hotmart.courses_error');
- } finally {
- loadingCourses = false;
- }
- }
-
- function getCourseDownloadStatus(courseId: string): "idle" | "downloading" | "complete" | "error" {
- const item = downloads.get(Number(courseId) || 0);
- if (!item) return "idle";
- const s = item.status;
- if (s === "queued" || s === "paused" || s === "seeding") return "downloading";
- return s;
- }
-
- function getCourseDownloadPercent(courseId: string): number {
- return downloads.get(Number(courseId) || 0)?.percent ?? 0;
- }
-
- async function downloadCourse(course: EstrategiaLdiCourse) {
- const status = getCourseDownloadStatus(course.id);
- if (status === "downloading") {
- showToast("info", $t("toast.download_already_active"));
- return;
- }
- if (status === "complete") return;
-
- const appSettings = getSettings();
- let outputDir: string | null = null;
-
- if (appSettings?.download.always_ask_path) {
- outputDir = await open({ directory: true, title: $t("hotmart.choose_folder") }) as string | null;
- if (!outputDir) return;
- } else {
- outputDir = appSettings?.download.default_output_dir ?? null;
- if (!outputDir) {
- outputDir = await open({ directory: true, title: $t("hotmart.choose_folder") }) as string | null;
- if (!outputDir) return;
- }
- }
-
- try {
- await pluginInvoke("courses", "start_estrategia_ldi_download", {
- courseJson: JSON.stringify(course),
- outputDir,
- });
- showToast("info", $t("toast.download_preparing"));
- } catch (e: any) {
- const msg = typeof e === "string" ? e : e.message ?? $t("common.error");
- showToast("error", msg);
- }
- }
-
- let refreshing = $state(false);
-
- async function refreshCourses() {
- refreshing = true;
- loadingCourses = true;
- coursesError = "";
- try {
- courses = await pluginInvoke("courses", "estrategia_ldi_refresh_courses");
- currentPage = 1;
- } catch (e: any) {
- coursesError = typeof e === "string" ? e : e.message ?? $t('hotmart.courses_error');
- } finally {
- loadingCourses = false;
- refreshing = false;
- }
- }
-</script>
-
-<a href="/courses" class="back-link">
- <svg viewBox="0 0 24 24" width="16" height="16" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
- <path d="M19 12H5" />
- <path d="M12 19l-7-7 7-7" />
- </svg>
- {$t("courses.back")}
-</a>
-
-{#if checking}
- <div class="page-center">
- <span class="spinner"></span>
- <span class="spinner-text">{$t('hotmart.checking_session')}</span>
- </div>
-{:else if loggedIn}
- <div class="page-logged">
- <div class="session-bar">
- <span class="session-info">
- {$t('hotmart.logged_as', { email: sessionEmail || "—" })}
- </span>
- <div class="session-actions">
- <button
- class="button"
- onclick={refreshCourses}
- disabled={refreshing}
- aria-label={$t('hotmart.refresh')}
- >
- <svg viewBox="0 0 24 24" width="14" height="14" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class:spinning={refreshing}>
- <path d="M21 2v6h-6" />
- <path d="M3 12a9 9 0 0115-6.7L21 8" />
- <path d="M3 22v-6h6" />
- <path d="M21 12a9 9 0 01-15 6.7L3 16" />
- </svg>
- </button>
- <button class="button" onclick={handleLogout}>{$t('hotmart.logout')}</button>
- </div>
- </div>
-
- {#if loadingCourses}
- <div class="spinner-section">
- <span class="spinner"></span>
- <span class="spinner-text">{$t('hotmart.loading_courses')}</span>
- </div>
- {:else if coursesError}
- <div class="error-section">
- <p class="error-msg">{coursesError}</p>
- <button class="button" onclick={loadCourses}>{$t('common.retry')}</button>
- </div>
- {:else if courses.length === 0}
- <p class="empty-text">{$t('hotmart.no_courses')}</p>
- {:else}
- <div class="courses-header">
- <h2>{$t('hotmart.courses_title')}</h2>
- <span class="subtext">{courses.length === 1 ? $t('hotmart.course_count_one', { count: courses.length }) : $t('hotmart.course_count', { count: courses.length })}</span>
- </div>
-
- <div class="courses-grid">
- {#each paginatedCourses as course (course.id)}
- <CourseCard
- name={course.name}
- price=""
- downloadStatus={getCourseDownloadStatus(course.id)}
- downloadPercent={getCourseDownloadPercent(course.id)}
- onDownload={() => downloadCourse(course)}
- />
- {/each}
- </div>
-
- {#if totalPages > 1}
- <div class="pagination">
- <span class="pagination-info">
- {$t('hotmart.page_of', { current: currentPage, total: totalPages })} &middot; {courses.length === 1 ? $t('hotmart.course_count_one', { count: courses.length }) : $t('hotmart.course_count', { count: courses.length })}
- </span>
- <div class="pagination-controls">
- <button
- class="button pagination-btn"
- disabled={currentPage <= 1}
- onclick={() => goToPage(currentPage - 1)}
- >
- &lt;
- </button>
-
- {#each pageNumbers() as page}
- {#if page === -1}
- <span class="pagination-ellipsis">&hellip;</span>
- {:else}
- <button
- class="button pagination-btn"
- class:active={page === currentPage}
- onclick={() => goToPage(page)}
- >
- {page}
- </button>
- {/if}
- {/each}
-
- <button
- class="button pagination-btn"
- disabled={currentPage >= totalPages}
- onclick={() => goToPage(currentPage + 1)}
- >
- &gt;
- </button>
- </div>
- </div>
- {/if}
- {/if}
- </div>
-{:else}
- <div class="page-center">
- <div class="login-card">
- <h2>Estrat&eacute;gia LDI</h2>
-
- <div class="form">
- <label class="field">
- <span class="field-label">Cookies JSON</span>
- <textarea
- class="input token-textarea"
- placeholder="Paste cookies JSON from browser extension or a raw token"
- bind:value={token}
- disabled={loading}
- rows="5"
- ></textarea>
- </label>
-
- <input
- type="file"
- accept=".json,.txt"
- class="hidden-file-input"
- bind:this={fileInput}
- onchange={onFileSelected}
- />
- <button class="button" onclick={() => fileInput?.click()} disabled={loading}>
- Import .json file
- </button>
-
- {#if error}
- <p class="error-msg">{error}</p>
- {/if}
-
- <button class="button" onclick={handleTokenLogin} disabled={loading || !token.trim()}>
- {#if loading}
- {$t('hotmart.authenticating')}
- {:else}
- {$t('hotmart.login')}
- {/if}
- </button>
- </div>
- </div>
- </div>
-{/if}
-
-<style>
- .back-link {
- display: inline-flex;
- align-items: center;
- gap: 6px;
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- margin-bottom: var(--padding);
- }
-
- @media (hover: hover) {
- .back-link:hover {
- color: var(--secondary);
- }
- }
-
- .page-center {
- display: flex;
- flex-direction: column;
- align-items: center;
- justify-content: center;
- min-height: calc(100vh - var(--padding) * 4 - 40px);
- gap: var(--padding);
- }
-
- .page-logged {
- display: flex;
- flex-direction: column;
- align-items: center;
- gap: calc(var(--padding) * 1.5);
- padding: calc(var(--padding) * 1.5);
- width: 100%;
- }
-
- .page-logged > :global(*) {
- width: 100%;
- max-width: 1200px;
- }
-
- .session-bar {
- display: flex;
- align-items: center;
- justify-content: space-between;
- }
-
- .session-info {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .session-actions {
- display: flex;
- gap: calc(var(--padding) / 2);
- }
-
- .session-bar :global(.button) {
- padding: calc(var(--padding) / 2) var(--padding);
- font-size: 12.5px;
- }
-
- .spinning {
- animation: spin 0.6s linear infinite;
- }
-
- .courses-header {
- display: flex;
- align-items: baseline;
- gap: var(--padding);
- }
-
- .courses-header h2 {
- margin-block: 0;
- }
-
- .subtext {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .courses-grid {
- display: grid;
- grid-template-columns: repeat(4, 1fr);
- gap: var(--padding);
- }
-
- @media (max-width: 1000px) {
- .courses-grid {
- grid-template-columns: repeat(3, 1fr);
- }
- }
-
- @media (max-width: 750px) {
- .courses-grid {
- grid-template-columns: repeat(2, 1fr);
- }
- }
-
- @media (max-width: 535px) {
- .courses-grid {
- grid-template-columns: 1fr;
- }
- }
-
- .pagination {
- display: flex;
- flex-direction: column;
- align-items: center;
- gap: var(--padding);
- padding-top: var(--padding);
- }
-
- .pagination-info {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .pagination-controls {
- display: flex;
- align-items: center;
- gap: calc(var(--padding) / 3);
- }
-
- .pagination-btn {
- min-width: 36px;
- height: 36px;
- padding: 0;
- display: flex;
- align-items: center;
- justify-content: center;
- font-size: 14.5px;
- }
-
- .pagination-ellipsis {
- min-width: 36px;
- text-align: center;
- color: var(--gray);
- font-size: 14.5px;
- }
-
- .login-card {
- width: 100%;
- max-width: 400px;
- background: var(--button-elevated);
- border-radius: var(--border-radius);
- padding: calc(var(--padding) * 2);
- display: flex;
- flex-direction: column;
- gap: calc(var(--padding) * 1.5);
- }
-
- .login-card h2 {
- margin-block: 0;
- }
-
- .hidden-file-input { display: none; }
-
- .token-textarea {
- resize: vertical;
- min-height: 80px;
- font-size: 11.5px;
- font-family: var(--font-mono);
- line-height: 1.5;
- }
-
- .form {
- display: flex;
- flex-direction: column;
- gap: var(--padding);
- }
-
- .field {
- display: flex;
- flex-direction: column;
- gap: calc(var(--padding) / 2);
- }
-
- .field-label {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .input {
- width: 100%;
- padding: var(--padding);
- font-size: 14.5px;
- background: var(--button);
- border-radius: var(--border-radius);
- color: var(--secondary);
- border: 1px solid var(--input-border);
- }
-
- .input::placeholder {
- color: var(--gray);
- }
-
- .input:focus-visible {
- border-color: var(--secondary);
- outline: none;
- }
-
- .input:disabled {
- opacity: 0.5;
- cursor: default;
- }
-
- .error-msg {
- color: var(--red);
- font-size: 12.5px;
- font-weight: 500;
- }
-
- .spinner-section {
- display: flex;
- flex-direction: column;
- align-items: center;
- gap: var(--padding);
- padding: calc(var(--padding) * 4) 0;
- }
-
- .spinner {
- width: 24px;
- height: 24px;
- border: 2px solid var(--input-border);
- border-top-color: var(--blue);
- border-radius: 50%;
- animation: spin 0.6s linear infinite;
- }
-
- @keyframes spin {
- to {
- transform: rotate(360deg);
- }
- }
-
- .spinner-text {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .error-section {
- display: flex;
- flex-direction: column;
- align-items: center;
- gap: var(--padding);
- padding: calc(var(--padding) * 2) 0;
- }
-
- .empty-text {
- color: var(--gray);
- font-size: 14.5px;
- text-align: center;
- padding: calc(var(--padding) * 4) 0;
- }
-</style>
diff --git a/src/routes/courses/estrategia-militares/+page.svelte b/src/routes/courses/estrategia-militares/+page.svelte
deleted file mode 100644
index 811c60f0..00000000
--- a/src/routes/courses/estrategia-militares/+page.svelte
+++ /dev/null
@@ -1,643 +0,0 @@
-<script lang="ts">
- import { pluginInvoke } from "$lib/plugin-invoke";
- import { open } from "@tauri-apps/plugin-dialog";
- import CourseCard from "$components/hotmart/CourseCard.svelte";
- import { showToast } from "$lib/stores/toast-store.svelte";
- import { getDownloads } from "$lib/stores/download-store.svelte";
- import { getSettings } from "$lib/stores/settings-store.svelte";
- import { t } from "$lib/i18n";
-
- let downloads = $derived(getDownloads());
-
- type EstrategiaMilitaresCourse = {
- id: string;
- name: string;
- slug: string;
- goal_id: string;
- };
-
- let token = $state("");
- let loading = $state(false);
- let error = $state("");
-
- let fileInput: HTMLInputElement = $state() as HTMLInputElement;
-
- function onFileSelected(e: Event) {
- const input = e.target as HTMLInputElement;
- const file = input.files?.[0];
- if (!file) return;
- const reader = new FileReader();
- reader.onload = () => { token = reader.result as string; };
- reader.readAsText(file);
- input.value = "";
- }
-
- let checking = $state(true);
- let loggedIn = $state(false);
- let sessionEmail = $state("");
-
- let courses: EstrategiaMilitaresCourse[] = $state([]);
- let loadingCourses = $state(false);
- let coursesError = $state("");
-
- const ITEMS_PER_PAGE = 12;
- let currentPage = $state(1);
-
- let totalPages = $derived(Math.max(1, Math.ceil(courses.length / ITEMS_PER_PAGE)));
- let paginatedCourses = $derived(
- courses.slice((currentPage - 1) * ITEMS_PER_PAGE, currentPage * ITEMS_PER_PAGE)
- );
-
- let pageNumbers = $derived((): number[] => {
- const pages: number[] = [];
- if (totalPages <= 7) {
- for (let i = 1; i <= totalPages; i++) pages.push(i);
- } else {
- pages.push(1);
- if (currentPage > 3) pages.push(-1);
- const start = Math.max(2, currentPage - 1);
- const end = Math.min(totalPages - 1, currentPage + 1);
- for (let i = start; i <= end; i++) pages.push(i);
- if (currentPage < totalPages - 2) pages.push(-1);
- pages.push(totalPages);
- }
- return pages;
- });
-
- function goToPage(page: number) {
- if (page >= 1 && page <= totalPages) {
- currentPage = page;
- }
- }
-
- $effect(() => {
- checkSession();
- });
-
- async function checkSession() {
- try {
- const result = await pluginInvoke<string>("courses", "estrategia_militares_check_session");
- sessionEmail = result;
- loggedIn = true;
- loadCourses();
- } catch {
- loggedIn = false;
- } finally {
- checking = false;
- }
- }
-
- async function handleTokenLogin() {
- if (!token.trim()) return;
- error = "";
- loading = true;
- try {
- const result = await pluginInvoke<string>("courses", "estrategia_militares_login_token", { token: token.trim() });
- sessionEmail = result || "Token";
- loggedIn = true;
- loadCourses();
- } catch (e: any) {
- error = typeof e === "string" ? e : e.message ?? $t('hotmart.unknown_error');
- } finally {
- loading = false;
- }
- }
-
- async function handleLogout() {
- try {
- await pluginInvoke("courses", "estrategia_militares_logout");
- } catch {
- }
- loggedIn = false;
- sessionEmail = "";
- courses = [];
- coursesError = "";
- currentPage = 1;
- }
-
- let searchQuery = $state("");
-
- async function loadCourses() {
- loadingCourses = true;
- coursesError = "";
- try {
- courses = await pluginInvoke("courses", "estrategia_militares_list_courses");
- currentPage = 1;
- } catch (e: any) {
- coursesError = typeof e === "string" ? e : e.message ?? $t('hotmart.courses_error');
- } finally {
- loadingCourses = false;
- }
- }
-
- async function handleSearch() {
- if (!searchQuery.trim()) return;
- loadingCourses = true;
- coursesError = "";
- try {
- courses = await pluginInvoke("courses", "estrategia_militares_search_courses", { query: searchQuery.trim() });
- currentPage = 1;
- } catch (e: any) {
- coursesError = typeof e === "string" ? e : e.message ?? "Search failed";
- } finally {
- loadingCourses = false;
- }
- }
-
- function getCourseDownloadStatus(courseId: string): "idle" | "downloading" | "complete" | "error" {
- const item = downloads.get(Number(courseId) || 0);
- if (!item) return "idle";
- const s = item.status;
- if (s === "queued" || s === "paused" || s === "seeding") return "downloading";
- return s;
- }
-
- function getCourseDownloadPercent(courseId: string): number {
- return downloads.get(Number(courseId) || 0)?.percent ?? 0;
- }
-
- async function downloadCourse(course: EstrategiaMilitaresCourse) {
- const status = getCourseDownloadStatus(course.id);
- if (status === "downloading") {
- showToast("info", $t("toast.download_already_active"));
- return;
- }
- if (status === "complete") return;
-
- const appSettings = getSettings();
- let outputDir: string | null = null;
-
- if (appSettings?.download.always_ask_path) {
- outputDir = await open({ directory: true, title: $t("hotmart.choose_folder") }) as string | null;
- if (!outputDir) return;
- } else {
- outputDir = appSettings?.download.default_output_dir ?? null;
- if (!outputDir) {
- outputDir = await open({ directory: true, title: $t("hotmart.choose_folder") }) as string | null;
- if (!outputDir) return;
- }
- }
-
- try {
- await pluginInvoke("courses", "start_estrategia_militares_course_download", {
- courseJson: JSON.stringify(course),
- outputDir,
- });
- showToast("info", $t("toast.download_preparing"));
- } catch (e: any) {
- const msg = typeof e === "string" ? e : e.message ?? $t("common.error");
- showToast("error", msg);
- }
- }
-
- let refreshing = $state(false);
-
- async function refreshCourses() {
- refreshing = true;
- loadingCourses = true;
- coursesError = "";
- try {
- courses = await pluginInvoke("courses", "estrategia_militares_refresh_courses");
- currentPage = 1;
- } catch (e: any) {
- coursesError = typeof e === "string" ? e : e.message ?? $t('hotmart.courses_error');
- } finally {
- loadingCourses = false;
- refreshing = false;
- }
- }
-</script>
-
-<a href="/courses" class="back-link">
- <svg viewBox="0 0 24 24" width="16" height="16" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
- <path d="M19 12H5" />
- <path d="M12 19l-7-7 7-7" />
- </svg>
- {$t("courses.back")}
-</a>
-
-{#if checking}
- <div class="page-center">
- <span class="spinner"></span>
- <span class="spinner-text">{$t('hotmart.checking_session')}</span>
- </div>
-{:else if loggedIn}
- <div class="page-logged">
- <div class="session-bar">
- <span class="session-info">
- {$t('hotmart.logged_as', { email: sessionEmail || "—" })}
- </span>
- <div class="session-actions">
- <button
- class="button"
- onclick={refreshCourses}
- disabled={refreshing}
- aria-label={$t('hotmart.refresh')}
- >
- <svg viewBox="0 0 24 24" width="14" height="14" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class:spinning={refreshing}>
- <path d="M21 2v6h-6" />
- <path d="M3 12a9 9 0 0115-6.7L21 8" />
- <path d="M3 22v-6h6" />
- <path d="M21 12a9 9 0 01-15 6.7L3 16" />
- </svg>
- </button>
- <button class="button" onclick={handleLogout}>{$t('hotmart.logout')}</button>
- </div>
- </div>
-
- <form class="search-bar" onsubmit={(e) => { e.preventDefault(); handleSearch(); }}>
- <input
- class="input search-input"
- type="text"
- placeholder="Search courses (e.g. Marinha, Exercito, FAB...)"
- bind:value={searchQuery}
- />
- <button class="button" type="submit" disabled={loadingCourses || !searchQuery.trim()}>
- Search
- </button>
- </form>
-
- {#if loadingCourses}
- <div class="spinner-section">
- <span class="spinner"></span>
- <span class="spinner-text">{$t('hotmart.loading_courses')}</span>
- </div>
- {:else if coursesError}
- <div class="error-section">
- <p class="error-msg">{coursesError}</p>
- <button class="button" onclick={loadCourses}>{$t('common.retry')}</button>
- </div>
- {:else if courses.length === 0}
- <p class="empty-text">{$t('hotmart.no_courses')}</p>
- {:else}
- <div class="courses-header">
- <h2>{$t('hotmart.courses_title')}</h2>
- <span class="subtext">{courses.length === 1 ? $t('hotmart.course_count_one', { count: courses.length }) : $t('hotmart.course_count', { count: courses.length })}</span>
- </div>
-
- <div class="courses-grid">
- {#each paginatedCourses as course (course.id)}
- <CourseCard
- name={course.name}
- price=""
- downloadStatus={getCourseDownloadStatus(course.id)}
- downloadPercent={getCourseDownloadPercent(course.id)}
- onDownload={() => downloadCourse(course)}
- />
- {/each}
- </div>
-
- {#if totalPages > 1}
- <div class="pagination">
- <span class="pagination-info">
- {$t('hotmart.page_of', { current: currentPage, total: totalPages })} &middot; {courses.length === 1 ? $t('hotmart.course_count_one', { count: courses.length }) : $t('hotmart.course_count', { count: courses.length })}
- </span>
- <div class="pagination-controls">
- <button
- class="button pagination-btn"
- disabled={currentPage <= 1}
- onclick={() => goToPage(currentPage - 1)}
- >
- &lt;
- </button>
-
- {#each pageNumbers() as page}
- {#if page === -1}
- <span class="pagination-ellipsis">&hellip;</span>
- {:else}
- <button
- class="button pagination-btn"
- class:active={page === currentPage}
- onclick={() => goToPage(page)}
- >
- {page}
- </button>
- {/if}
- {/each}
-
- <button
- class="button pagination-btn"
- disabled={currentPage >= totalPages}
- onclick={() => goToPage(currentPage + 1)}
- >
- &gt;
- </button>
- </div>
- </div>
- {/if}
- {/if}
- </div>
-{:else}
- <div class="page-center">
- <div class="login-card">
- <h2>Estrat&eacute;gia Militares</h2>
-
- <div class="form">
- <label class="field">
- <span class="field-label">Cookies JSON</span>
- <textarea
- class="input token-textarea"
- placeholder="Paste cookies JSON from browser extension or a raw token"
- bind:value={token}
- disabled={loading}
- rows="5"
- ></textarea>
- </label>
-
- <input
- type="file"
- accept=".json,.txt"
- class="hidden-file-input"
- bind:this={fileInput}
- onchange={onFileSelected}
- />
- <button class="button" onclick={() => fileInput?.click()} disabled={loading}>
- Import .json file
- </button>
-
- {#if error}
- <p class="error-msg">{error}</p>
- {/if}
-
- <button class="button" onclick={handleTokenLogin} disabled={loading || !token.trim()}>
- {#if loading}
- {$t('hotmart.authenticating')}
- {:else}
- {$t('hotmart.login')}
- {/if}
- </button>
- </div>
- </div>
- </div>
-{/if}
-
-<style>
- .search-bar {
- display: flex;
- gap: calc(var(--padding) / 2);
- width: 100%;
- }
-
- .search-input {
- flex: 1;
- }
-
- .back-link {
- display: inline-flex;
- align-items: center;
- gap: 6px;
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- margin-bottom: var(--padding);
- }
-
- @media (hover: hover) {
- .back-link:hover {
- color: var(--secondary);
- }
- }
-
- .page-center {
- display: flex;
- flex-direction: column;
- align-items: center;
- justify-content: center;
- min-height: calc(100vh - var(--padding) * 4 - 40px);
- gap: var(--padding);
- }
-
- .page-logged {
- display: flex;
- flex-direction: column;
- align-items: center;
- gap: calc(var(--padding) * 1.5);
- padding: calc(var(--padding) * 1.5);
- width: 100%;
- }
-
- .page-logged > :global(*) {
- width: 100%;
- max-width: 1200px;
- }
-
- .session-bar {
- display: flex;
- align-items: center;
- justify-content: space-between;
- }
-
- .session-info {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .session-actions {
- display: flex;
- gap: calc(var(--padding) / 2);
- }
-
- .session-bar :global(.button) {
- padding: calc(var(--padding) / 2) var(--padding);
- font-size: 12.5px;
- }
-
- .spinning {
- animation: spin 0.6s linear infinite;
- }
-
- .courses-header {
- display: flex;
- align-items: baseline;
- gap: var(--padding);
- }
-
- .courses-header h2 {
- margin-block: 0;
- }
-
- .subtext {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .courses-grid {
- display: grid;
- grid-template-columns: repeat(4, 1fr);
- gap: var(--padding);
- }
-
- @media (max-width: 1000px) {
- .courses-grid {
- grid-template-columns: repeat(3, 1fr);
- }
- }
-
- @media (max-width: 750px) {
- .courses-grid {
- grid-template-columns: repeat(2, 1fr);
- }
- }
-
- @media (max-width: 535px) {
- .courses-grid {
- grid-template-columns: 1fr;
- }
- }
-
- .pagination {
- display: flex;
- flex-direction: column;
- align-items: center;
- gap: var(--padding);
- padding-top: var(--padding);
- }
-
- .pagination-info {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .pagination-controls {
- display: flex;
- align-items: center;
- gap: calc(var(--padding) / 3);
- }
-
- .pagination-btn {
- min-width: 36px;
- height: 36px;
- padding: 0;
- display: flex;
- align-items: center;
- justify-content: center;
- font-size: 14.5px;
- }
-
- .pagination-ellipsis {
- min-width: 36px;
- text-align: center;
- color: var(--gray);
- font-size: 14.5px;
- }
-
- .login-card {
- width: 100%;
- max-width: 400px;
- background: var(--button-elevated);
- border-radius: var(--border-radius);
- padding: calc(var(--padding) * 2);
- display: flex;
- flex-direction: column;
- gap: calc(var(--padding) * 1.5);
- }
-
- .login-card h2 {
- margin-block: 0;
- }
-
- .hidden-file-input { display: none; }
-
- .token-textarea {
- resize: vertical;
- min-height: 80px;
- font-size: 11.5px;
- font-family: var(--font-mono);
- line-height: 1.5;
- }
-
- .form {
- display: flex;
- flex-direction: column;
- gap: var(--padding);
- }
-
- .field {
- display: flex;
- flex-direction: column;
- gap: calc(var(--padding) / 2);
- }
-
- .field-label {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .input {
- width: 100%;
- padding: var(--padding);
- font-size: 14.5px;
- background: var(--button);
- border-radius: var(--border-radius);
- color: var(--secondary);
- border: 1px solid var(--input-border);
- }
-
- .input::placeholder {
- color: var(--gray);
- }
-
- .input:focus-visible {
- border-color: var(--secondary);
- outline: none;
- }
-
- .input:disabled {
- opacity: 0.5;
- cursor: default;
- }
-
- .error-msg {
- color: var(--red);
- font-size: 12.5px;
- font-weight: 500;
- }
-
- .spinner-section {
- display: flex;
- flex-direction: column;
- align-items: center;
- gap: var(--padding);
- padding: calc(var(--padding) * 4) 0;
- }
-
- .spinner {
- width: 24px;
- height: 24px;
- border: 2px solid var(--input-border);
- border-top-color: var(--blue);
- border-radius: 50%;
- animation: spin 0.6s linear infinite;
- }
-
- @keyframes spin {
- to {
- transform: rotate(360deg);
- }
- }
-
- .spinner-text {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .error-section {
- display: flex;
- flex-direction: column;
- align-items: center;
- gap: var(--padding);
- padding: calc(var(--padding) * 2) 0;
- }
-
- .empty-text {
- color: var(--gray);
- font-size: 14.5px;
- text-align: center;
- padding: calc(var(--padding) * 4) 0;
- }
-</style>
diff --git a/src/routes/courses/fluencyacademy/+page.svelte b/src/routes/courses/fluencyacademy/+page.svelte
deleted file mode 100644
index b5b1cebf..00000000
--- a/src/routes/courses/fluencyacademy/+page.svelte
+++ /dev/null
@@ -1,701 +0,0 @@
-<script lang="ts">
- import { pluginInvoke } from "$lib/plugin-invoke";
- import { open } from "@tauri-apps/plugin-dialog";
- import CourseCard from "$components/hotmart/CourseCard.svelte";
- import { showToast } from "$lib/stores/toast-store.svelte";
- import { getDownloads } from "$lib/stores/download-store.svelte";
- import { getSettings } from "$lib/stores/settings-store.svelte";
- import { t } from "$lib/i18n";
-
- let downloads = $derived(getDownloads());
-
- type FluencyCourse = {
- id: string;
- name: string;
- program_id: string;
- };
-
- let email = $state("");
- let password = $state("");
- let token = $state("");
- let loading = $state(false);
- let error = $state("");
-
- let checking = $state(true);
- let loggedIn = $state(false);
- let sessionEmail = $state("");
-
- let loginMode = $state<"credentials" | "token">("credentials");
-
- let fileInput: HTMLInputElement = $state() as HTMLInputElement;
-
- function onFileSelected(e: Event) {
- const input = e.target as HTMLInputElement;
- const file = input.files?.[0];
- if (!file) return;
- const reader = new FileReader();
- reader.onload = () => { token = reader.result as string; };
- reader.readAsText(file);
- input.value = "";
- }
-
- let courses: FluencyCourse[] = $state([]);
- let loadingCourses = $state(false);
- let coursesError = $state("");
-
- const ITEMS_PER_PAGE = 12;
- let currentPage = $state(1);
-
- let totalPages = $derived(Math.max(1, Math.ceil(courses.length / ITEMS_PER_PAGE)));
- let paginatedCourses = $derived(
- courses.slice((currentPage - 1) * ITEMS_PER_PAGE, currentPage * ITEMS_PER_PAGE)
- );
-
- let pageNumbers = $derived((): number[] => {
- const pages: number[] = [];
- if (totalPages <= 7) {
- for (let i = 1; i <= totalPages; i++) pages.push(i);
- } else {
- pages.push(1);
- if (currentPage > 3) pages.push(-1);
- const start = Math.max(2, currentPage - 1);
- const end = Math.min(totalPages - 1, currentPage + 1);
- for (let i = start; i <= end; i++) pages.push(i);
- if (currentPage < totalPages - 2) pages.push(-1);
- pages.push(totalPages);
- }
- return pages;
- });
-
- function goToPage(page: number) {
- if (page >= 1 && page <= totalPages) {
- currentPage = page;
- }
- }
-
- $effect(() => {
- checkSession();
- });
-
- async function checkSession() {
- try {
- const result = await pluginInvoke<string>("courses", "fluencyacademy_check_session");
- sessionEmail = result;
- loggedIn = true;
- loadCourses();
- } catch {
- loggedIn = false;
- } finally {
- checking = false;
- }
- }
-
- async function handleLogin() {
- error = "";
- loading = true;
- try {
- const result = await pluginInvoke<string>("courses", "fluencyacademy_login", { email, password });
- sessionEmail = result || email;
- loggedIn = true;
- loadCourses();
- } catch (e: any) {
- error = typeof e === "string" ? e : e.message ?? $t('hotmart.unknown_error');
- } finally {
- loading = false;
- }
- }
-
- async function handleTokenLogin() {
- if (!token.trim()) return;
- error = "";
- loading = true;
- try {
- const result = await pluginInvoke<string>("courses", "fluencyacademy_login_token", { token: token.trim() });
- sessionEmail = result || "Token";
- loggedIn = true;
- loadCourses();
- } catch (e: any) {
- error = typeof e === "string" ? e : e.message ?? $t('hotmart.unknown_error');
- } finally {
- loading = false;
- }
- }
-
- async function handleLogout() {
- try {
- await pluginInvoke("courses", "fluencyacademy_logout");
- } catch {
- }
- loggedIn = false;
- sessionEmail = "";
- courses = [];
- coursesError = "";
- currentPage = 1;
- }
-
- async function loadCourses() {
- loadingCourses = true;
- coursesError = "";
- try {
- courses = await pluginInvoke("courses", "fluencyacademy_list_courses");
- currentPage = 1;
- } catch (e: any) {
- coursesError = typeof e === "string" ? e : e.message ?? $t('hotmart.courses_error');
- } finally {
- loadingCourses = false;
- }
- }
-
- function getCourseDownloadStatus(courseId: string): "idle" | "downloading" | "complete" | "error" {
- const numId = Number(courseId) || 0;
- const item = downloads.get(numId);
- if (!item) return "idle";
- const s = item.status;
- if (s === "queued" || s === "paused" || s === "seeding") return "downloading";
- return s;
- }
-
- function getCourseDownloadPercent(courseId: string): number {
- const numId = Number(courseId) || 0;
- return downloads.get(numId)?.percent ?? 0;
- }
-
- async function downloadCourse(course: FluencyCourse) {
- const status = getCourseDownloadStatus(course.id);
- if (status === "downloading") {
- showToast("info", $t("toast.download_already_active"));
- return;
- }
- if (status === "complete") return;
-
- const appSettings = getSettings();
- let outputDir: string | null = null;
-
- if (appSettings?.download.always_ask_path) {
- outputDir = await open({ directory: true, title: $t("hotmart.choose_folder") }) as string | null;
- if (!outputDir) return;
- } else {
- outputDir = appSettings?.download.default_output_dir ?? null;
- if (!outputDir) {
- outputDir = await open({ directory: true, title: $t("hotmart.choose_folder") }) as string | null;
- if (!outputDir) return;
- }
- }
-
- try {
- await pluginInvoke("courses", "start_fluencyacademy_download", {
- courseJson: JSON.stringify(course),
- outputDir,
- });
- showToast("info", $t("toast.download_preparing"));
- } catch (e: any) {
- const msg = typeof e === "string" ? e : e.message ?? $t("common.error");
- showToast("error", msg);
- }
- }
-
- let refreshing = $state(false);
-
- async function refreshCourses() {
- refreshing = true;
- loadingCourses = true;
- coursesError = "";
- try {
- courses = await pluginInvoke("courses", "fluencyacademy_refresh_courses");
- currentPage = 1;
- } catch (e: any) {
- coursesError = typeof e === "string" ? e : e.message ?? $t('hotmart.courses_error');
- } finally {
- loadingCourses = false;
- refreshing = false;
- }
- }
-</script>
-
-<a href="/courses" class="back-link">
- <svg viewBox="0 0 24 24" width="16" height="16" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
- <path d="M19 12H5" />
- <path d="M12 19l-7-7 7-7" />
- </svg>
- {$t("courses.back")}
-</a>
-
-{#if checking}
- <div class="page-center">
- <span class="spinner"></span>
- <span class="spinner-text">{$t('hotmart.checking_session')}</span>
- </div>
-{:else if loggedIn}
- <div class="page-logged">
- <div class="session-bar">
- <span class="session-info">
- {$t('hotmart.logged_as', { email: sessionEmail || "—" })}
- </span>
- <div class="session-actions">
- <button
- class="button"
- onclick={refreshCourses}
- disabled={refreshing}
- aria-label={$t('hotmart.refresh')}
- >
- <svg viewBox="0 0 24 24" width="14" height="14" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class:spinning={refreshing}>
- <path d="M21 2v6h-6" />
- <path d="M3 12a9 9 0 0115-6.7L21 8" />
- <path d="M3 22v-6h6" />
- <path d="M21 12a9 9 0 01-15 6.7L3 16" />
- </svg>
- </button>
- <button class="button" onclick={handleLogout}>{$t('hotmart.logout')}</button>
- </div>
- </div>
-
- {#if loadingCourses}
- <div class="spinner-section">
- <span class="spinner"></span>
- <span class="spinner-text">{$t('hotmart.loading_courses')}</span>
- </div>
- {:else if coursesError}
- <div class="error-section">
- <p class="error-msg">{coursesError}</p>
- <button class="button" onclick={loadCourses}>{$t('common.retry')}</button>
- </div>
- {:else if courses.length === 0}
- <p class="empty-text">{$t('hotmart.no_courses')}</p>
- {:else}
- <div class="courses-header">
- <h2>{$t('hotmart.courses_title')}</h2>
- <span class="subtext">{courses.length === 1 ? $t('hotmart.course_count_one', { count: courses.length }) : $t('hotmart.course_count', { count: courses.length })}</span>
- </div>
-
- <div class="courses-grid">
- {#each paginatedCourses as course (course.id)}
- <CourseCard
- name={course.name}
- price=""
- downloadStatus={getCourseDownloadStatus(course.id)}
- downloadPercent={getCourseDownloadPercent(course.id)}
- onDownload={() => downloadCourse(course)}
- />
- {/each}
- </div>
-
- {#if totalPages > 1}
- <div class="pagination">
- <span class="pagination-info">
- {$t('hotmart.page_of', { current: currentPage, total: totalPages })} &middot; {courses.length === 1 ? $t('hotmart.course_count_one', { count: courses.length }) : $t('hotmart.course_count', { count: courses.length })}
- </span>
- <div class="pagination-controls">
- <button
- class="button pagination-btn"
- disabled={currentPage <= 1}
- onclick={() => goToPage(currentPage - 1)}
- >
- &lt;
- </button>
-
- {#each pageNumbers() as page}
- {#if page === -1}
- <span class="pagination-ellipsis">&hellip;</span>
- {:else}
- <button
- class="button pagination-btn"
- class:active={page === currentPage}
- onclick={() => goToPage(page)}
- >
- {page}
- </button>
- {/if}
- {/each}
-
- <button
- class="button pagination-btn"
- disabled={currentPage >= totalPages}
- onclick={() => goToPage(currentPage + 1)}
- >
- &gt;
- </button>
- </div>
- </div>
- {/if}
- {/if}
- </div>
-{:else}
- <div class="page-center">
- <div class="login-card">
- <h2>Fluency Academy</h2>
-
- <div class="login-tabs">
- <button
- class="button login-tab"
- class:active={loginMode === "credentials"}
- onclick={() => { loginMode = "credentials"; error = ""; }}
- >
- Email & Password
- </button>
- <button
- class="button login-tab"
- class:active={loginMode === "token"}
- onclick={() => { loginMode = "token"; error = ""; }}
- >
- Token
- </button>
- </div>
-
- {#if loginMode === "credentials"}
- <form class="form" onsubmit={(e) => { e.preventDefault(); handleLogin(); }}>
- <label class="field">
- <span class="field-label">{$t('hotmart.email_label')}</span>
- <input
- type="email"
- placeholder={$t('hotmart.email_placeholder')}
- bind:value={email}
- class="input"
- disabled={loading}
- required
- />
- </label>
- <label class="field">
- <span class="field-label">{$t('hotmart.password_label')}</span>
- <input
- type="password"
- placeholder={$t('hotmart.password_placeholder')}
- bind:value={password}
- class="input"
- disabled={loading}
- required
- />
- </label>
-
- {#if error}
- <p class="error-msg">{error}</p>
- {/if}
-
- <button type="submit" class="button" disabled={loading}>
- {#if loading}
- {$t('hotmart.authenticating')}
- {:else}
- {$t('hotmart.login')}
- {/if}
- </button>
- </form>
- {:else}
- <div class="form">
- <label class="field">
- <span class="field-label">Cookies JSON</span>
- <textarea
- class="input token-textarea"
- placeholder="Paste cookies JSON from browser extension or a raw token"
- bind:value={token}
- disabled={loading}
- rows="5"
- ></textarea>
- </label>
-
- <input
- type="file"
- accept=".json,.txt"
- class="hidden-file-input"
- bind:this={fileInput}
- onchange={onFileSelected}
- />
- <button class="button" onclick={() => fileInput?.click()} disabled={loading}>
- Import .json file
- </button>
-
- {#if error}
- <p class="error-msg">{error}</p>
- {/if}
-
- <button class="button" onclick={handleTokenLogin} disabled={loading || !token.trim()}>
- {#if loading}
- {$t('hotmart.authenticating')}
- {:else}
- {$t('hotmart.login')}
- {/if}
- </button>
- </div>
- {/if}
- </div>
- </div>
-{/if}
-
-<style>
- .back-link {
- display: inline-flex;
- align-items: center;
- gap: 6px;
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- margin-bottom: var(--padding);
- }
-
- @media (hover: hover) {
- .back-link:hover {
- color: var(--secondary);
- }
- }
-
- .page-center {
- display: flex;
- flex-direction: column;
- align-items: center;
- justify-content: center;
- min-height: calc(100vh - var(--padding) * 4 - 40px);
- gap: var(--padding);
- }
-
- .page-logged {
- display: flex;
- flex-direction: column;
- align-items: center;
- gap: calc(var(--padding) * 1.5);
- padding: calc(var(--padding) * 1.5);
- width: 100%;
- }
-
- .page-logged > :global(*) {
- width: 100%;
- max-width: 1200px;
- }
-
- .session-bar {
- display: flex;
- align-items: center;
- justify-content: space-between;
- }
-
- .session-info {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .session-actions {
- display: flex;
- gap: calc(var(--padding) / 2);
- }
-
- .session-bar :global(.button) {
- padding: calc(var(--padding) / 2) var(--padding);
- font-size: 12.5px;
- }
-
- .spinning {
- animation: spin 0.6s linear infinite;
- }
-
- .courses-header {
- display: flex;
- align-items: baseline;
- gap: var(--padding);
- }
-
- .courses-header h2 {
- margin-block: 0;
- }
-
- .subtext {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .courses-grid {
- display: grid;
- grid-template-columns: repeat(4, 1fr);
- gap: var(--padding);
- }
-
- @media (max-width: 1000px) {
- .courses-grid {
- grid-template-columns: repeat(3, 1fr);
- }
- }
-
- @media (max-width: 750px) {
- .courses-grid {
- grid-template-columns: repeat(2, 1fr);
- }
- }
-
- @media (max-width: 535px) {
- .courses-grid {
- grid-template-columns: 1fr;
- }
- }
-
- .pagination {
- display: flex;
- flex-direction: column;
- align-items: center;
- gap: var(--padding);
- padding-top: var(--padding);
- }
-
- .pagination-info {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .pagination-controls {
- display: flex;
- align-items: center;
- gap: calc(var(--padding) / 3);
- }
-
- .pagination-btn {
- min-width: 36px;
- height: 36px;
- padding: 0;
- display: flex;
- align-items: center;
- justify-content: center;
- font-size: 14.5px;
- }
-
- .pagination-ellipsis {
- min-width: 36px;
- text-align: center;
- color: var(--gray);
- font-size: 14.5px;
- }
-
- .login-card {
- width: 100%;
- max-width: 400px;
- background: var(--button-elevated);
- border-radius: var(--border-radius);
- padding: calc(var(--padding) * 2);
- display: flex;
- flex-direction: column;
- gap: calc(var(--padding) * 1.5);
- }
-
- .login-card h2 {
- margin-block: 0;
- }
-
- .login-tabs {
- display: flex;
- gap: 0;
- }
-
- .login-tab {
- flex: 1;
- border-radius: 0;
- font-size: 12.5px;
- padding: calc(var(--padding) * 0.75) var(--padding);
- }
-
- .login-tab:first-child {
- border-radius: var(--border-radius) 0 0 var(--border-radius);
- }
-
- .login-tab:last-child {
- border-radius: 0 var(--border-radius) var(--border-radius) 0;
- }
-
- .hidden-file-input { display: none; }
-
- .token-textarea {
- resize: vertical;
- min-height: 80px;
- font-size: 11.5px;
- font-family: var(--font-mono);
- line-height: 1.5;
- }
-
- .form {
- display: flex;
- flex-direction: column;
- gap: var(--padding);
- }
-
- .field {
- display: flex;
- flex-direction: column;
- gap: calc(var(--padding) / 2);
- }
-
- .field-label {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .input {
- width: 100%;
- padding: var(--padding);
- font-size: 14.5px;
- background: var(--button);
- border-radius: var(--border-radius);
- color: var(--secondary);
- border: 1px solid var(--input-border);
- }
-
- .input::placeholder {
- color: var(--gray);
- }
-
- .input:focus-visible {
- border-color: var(--secondary);
- outline: none;
- }
-
- .input:disabled {
- opacity: 0.5;
- cursor: default;
- }
-
- .error-msg {
- color: var(--red);
- font-size: 12.5px;
- font-weight: 500;
- }
-
- .spinner-section {
- display: flex;
- flex-direction: column;
- align-items: center;
- gap: var(--padding);
- padding: calc(var(--padding) * 4) 0;
- }
-
- .spinner {
- width: 24px;
- height: 24px;
- border: 2px solid var(--input-border);
- border-top-color: var(--blue);
- border-radius: 50%;
- animation: spin 0.6s linear infinite;
- }
-
- @keyframes spin {
- to {
- transform: rotate(360deg);
- }
- }
-
- .spinner-text {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .error-section {
- display: flex;
- flex-direction: column;
- align-items: center;
- gap: var(--padding);
- padding: calc(var(--padding) * 2) 0;
- }
-
- .empty-text {
- color: var(--gray);
- font-size: 14.5px;
- text-align: center;
- padding: calc(var(--padding) * 4) 0;
- }
-</style>
diff --git a/src/routes/courses/grancursos/+page.svelte b/src/routes/courses/grancursos/+page.svelte
deleted file mode 100644
index c88f401c..00000000
--- a/src/routes/courses/grancursos/+page.svelte
+++ /dev/null
@@ -1,603 +0,0 @@
-<script lang="ts">
- import { pluginInvoke } from "$lib/plugin-invoke";
- import { open } from "@tauri-apps/plugin-dialog";
- import CourseCard from "$components/hotmart/CourseCard.svelte";
- import { showToast } from "$lib/stores/toast-store.svelte";
- import { getDownloads } from "$lib/stores/download-store.svelte";
- import { getSettings } from "$lib/stores/settings-store.svelte";
- import { t } from "$lib/i18n";
-
- let downloads = $derived(getDownloads());
-
- type GranCursosCourse = {
- id: number;
- name: string;
- };
-
- let token = $state("");
- let loading = $state(false);
- let error = $state("");
-
- let fileInput: HTMLInputElement = $state() as HTMLInputElement;
-
- function onFileSelected(e: Event) {
- const input = e.target as HTMLInputElement;
- const file = input.files?.[0];
- if (!file) return;
- const reader = new FileReader();
- reader.onload = () => { token = reader.result as string; };
- reader.readAsText(file);
- input.value = "";
- }
-
- let checking = $state(true);
- let loggedIn = $state(false);
- let sessionEmail = $state("");
-
- let courses: GranCursosCourse[] = $state([]);
- let loadingCourses = $state(false);
- let coursesError = $state("");
-
- const ITEMS_PER_PAGE = 12;
- let currentPage = $state(1);
-
- let totalPages = $derived(Math.max(1, Math.ceil(courses.length / ITEMS_PER_PAGE)));
- let paginatedCourses = $derived(
- courses.slice((currentPage - 1) * ITEMS_PER_PAGE, currentPage * ITEMS_PER_PAGE)
- );
-
- let pageNumbers = $derived((): number[] => {
- const pages: number[] = [];
- if (totalPages <= 7) {
- for (let i = 1; i <= totalPages; i++) pages.push(i);
- } else {
- pages.push(1);
- if (currentPage > 3) pages.push(-1);
- const start = Math.max(2, currentPage - 1);
- const end = Math.min(totalPages - 1, currentPage + 1);
- for (let i = start; i <= end; i++) pages.push(i);
- if (currentPage < totalPages - 2) pages.push(-1);
- pages.push(totalPages);
- }
- return pages;
- });
-
- function goToPage(page: number) {
- if (page >= 1 && page <= totalPages) {
- currentPage = page;
- }
- }
-
- $effect(() => {
- checkSession();
- });
-
- async function checkSession() {
- try {
- const result = await pluginInvoke<string>("courses", "grancursos_check_session");
- sessionEmail = result;
- loggedIn = true;
- loadCourses();
- } catch {
- loggedIn = false;
- } finally {
- checking = false;
- }
- }
-
- async function handleTokenLogin() {
- if (!token.trim()) return;
- error = "";
- loading = true;
- try {
- const result = await pluginInvoke<string>("courses", "grancursos_login_token", { token: token.trim() });
- sessionEmail = result || "Token";
- loggedIn = true;
- loadCourses();
- } catch (e: any) {
- error = typeof e === "string" ? e : e.message ?? $t('hotmart.unknown_error');
- } finally {
- loading = false;
- }
- }
-
- async function handleLogout() {
- try {
- await pluginInvoke("courses", "grancursos_logout");
- } catch {
- }
- loggedIn = false;
- sessionEmail = "";
- courses = [];
- coursesError = "";
- currentPage = 1;
- }
-
- async function loadCourses() {
- loadingCourses = true;
- coursesError = "";
- try {
- courses = await pluginInvoke("courses", "grancursos_list_courses");
- currentPage = 1;
- } catch (e: any) {
- coursesError = typeof e === "string" ? e : e.message ?? $t('hotmart.courses_error');
- } finally {
- loadingCourses = false;
- }
- }
-
- function getCourseDownloadStatus(courseId: number): "idle" | "downloading" | "complete" | "error" {
- const item = downloads.get(courseId);
- if (!item) return "idle";
- const s = item.status;
- if (s === "queued" || s === "paused" || s === "seeding") return "downloading";
- return s;
- }
-
- function getCourseDownloadPercent(courseId: number): number {
- return downloads.get(courseId)?.percent ?? 0;
- }
-
- async function downloadCourse(course: GranCursosCourse) {
- const status = getCourseDownloadStatus(course.id);
- if (status === "downloading") {
- showToast("info", $t("toast.download_already_active"));
- return;
- }
- if (status === "complete") return;
-
- const appSettings = getSettings();
- let outputDir: string | null = null;
-
- if (appSettings?.download.always_ask_path) {
- outputDir = await open({ directory: true, title: $t("hotmart.choose_folder") }) as string | null;
- if (!outputDir) return;
- } else {
- outputDir = appSettings?.download.default_output_dir ?? null;
- if (!outputDir) {
- outputDir = await open({ directory: true, title: $t("hotmart.choose_folder") }) as string | null;
- if (!outputDir) return;
- }
- }
-
- try {
- await pluginInvoke("courses", "start_grancursos_download", {
- courseJson: JSON.stringify(course),
- outputDir,
- });
- showToast("info", $t("toast.download_preparing"));
- } catch (e: any) {
- const msg = typeof e === "string" ? e : e.message ?? $t("common.error");
- showToast("error", msg);
- }
- }
-
- let refreshing = $state(false);
-
- async function refreshCourses() {
- refreshing = true;
- loadingCourses = true;
- coursesError = "";
- try {
- courses = await pluginInvoke("courses", "grancursos_refresh_courses");
- currentPage = 1;
- } catch (e: any) {
- coursesError = typeof e === "string" ? e : e.message ?? $t('hotmart.courses_error');
- } finally {
- loadingCourses = false;
- refreshing = false;
- }
- }
-</script>
-
-<a href="/courses" class="back-link">
- <svg viewBox="0 0 24 24" width="16" height="16" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
- <path d="M19 12H5" />
- <path d="M12 19l-7-7 7-7" />
- </svg>
- {$t("courses.back")}
-</a>
-
-{#if checking}
- <div class="page-center">
- <span class="spinner"></span>
- <span class="spinner-text">{$t('hotmart.checking_session')}</span>
- </div>
-{:else if loggedIn}
- <div class="page-logged">
- <div class="session-bar">
- <span class="session-info">
- {$t('hotmart.logged_as', { email: sessionEmail || "—" })}
- </span>
- <div class="session-actions">
- <button
- class="button"
- onclick={refreshCourses}
- disabled={refreshing}
- aria-label={$t('hotmart.refresh')}
- >
- <svg viewBox="0 0 24 24" width="14" height="14" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class:spinning={refreshing}>
- <path d="M21 2v6h-6" />
- <path d="M3 12a9 9 0 0115-6.7L21 8" />
- <path d="M3 22v-6h6" />
- <path d="M21 12a9 9 0 01-15 6.7L3 16" />
- </svg>
- </button>
- <button class="button" onclick={handleLogout}>{$t('hotmart.logout')}</button>
- </div>
- </div>
-
- {#if loadingCourses}
- <div class="spinner-section">
- <span class="spinner"></span>
- <span class="spinner-text">{$t('hotmart.loading_courses')}</span>
- </div>
- {:else if coursesError}
- <div class="error-section">
- <p class="error-msg">{coursesError}</p>
- <button class="button" onclick={loadCourses}>{$t('common.retry')}</button>
- </div>
- {:else if courses.length === 0}
- <p class="empty-text">{$t('hotmart.no_courses')}</p>
- {:else}
- <div class="courses-header">
- <h2>{$t('hotmart.courses_title')}</h2>
- <span class="subtext">{courses.length === 1 ? $t('hotmart.course_count_one', { count: courses.length }) : $t('hotmart.course_count', { count: courses.length })}</span>
- </div>
-
- <div class="courses-grid">
- {#each paginatedCourses as course (course.id)}
- <CourseCard
- name={course.name}
- price=""
- downloadStatus={getCourseDownloadStatus(course.id)}
- downloadPercent={getCourseDownloadPercent(course.id)}
- onDownload={() => downloadCourse(course)}
- />
- {/each}
- </div>
-
- {#if totalPages > 1}
- <div class="pagination">
- <span class="pagination-info">
- {$t('hotmart.page_of', { current: currentPage, total: totalPages })} &middot; {courses.length === 1 ? $t('hotmart.course_count_one', { count: courses.length }) : $t('hotmart.course_count', { count: courses.length })}
- </span>
- <div class="pagination-controls">
- <button
- class="button pagination-btn"
- disabled={currentPage <= 1}
- onclick={() => goToPage(currentPage - 1)}
- >
- &lt;
- </button>
-
- {#each pageNumbers() as page}
- {#if page === -1}
- <span class="pagination-ellipsis">&hellip;</span>
- {:else}
- <button
- class="button pagination-btn"
- class:active={page === currentPage}
- onclick={() => goToPage(page)}
- >
- {page}
- </button>
- {/if}
- {/each}
-
- <button
- class="button pagination-btn"
- disabled={currentPage >= totalPages}
- onclick={() => goToPage(currentPage + 1)}
- >
- &gt;
- </button>
- </div>
- </div>
- {/if}
- {/if}
- </div>
-{:else}
- <div class="page-center">
- <div class="login-card">
- <h2>Gran Cursos</h2>
-
- <div class="form">
- <label class="field">
- <span class="field-label">Cookies JSON</span>
- <textarea
- class="input token-textarea"
- placeholder="Paste cookies JSON from browser extension or a raw token"
- bind:value={token}
- disabled={loading}
- rows="5"
- ></textarea>
- </label>
-
- <input
- type="file"
- accept=".json,.txt"
- class="hidden-file-input"
- bind:this={fileInput}
- onchange={onFileSelected}
- />
- <button class="button" onclick={() => fileInput?.click()} disabled={loading}>
- Import .json file
- </button>
-
- {#if error}
- <p class="error-msg">{error}</p>
- {/if}
-
- <button class="button" onclick={handleTokenLogin} disabled={loading || !token.trim()}>
- {#if loading}
- {$t('hotmart.authenticating')}
- {:else}
- {$t('hotmart.login')}
- {/if}
- </button>
- </div>
- </div>
- </div>
-{/if}
-
-<style>
- .back-link {
- display: inline-flex;
- align-items: center;
- gap: 6px;
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- margin-bottom: var(--padding);
- }
-
- @media (hover: hover) {
- .back-link:hover {
- color: var(--secondary);
- }
- }
-
- .page-center {
- display: flex;
- flex-direction: column;
- align-items: center;
- justify-content: center;
- min-height: calc(100vh - var(--padding) * 4 - 40px);
- gap: var(--padding);
- }
-
- .page-logged {
- display: flex;
- flex-direction: column;
- align-items: center;
- gap: calc(var(--padding) * 1.5);
- padding: calc(var(--padding) * 1.5);
- width: 100%;
- }
-
- .page-logged > :global(*) {
- width: 100%;
- max-width: 1200px;
- }
-
- .session-bar {
- display: flex;
- align-items: center;
- justify-content: space-between;
- }
-
- .session-info {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .session-actions {
- display: flex;
- gap: calc(var(--padding) / 2);
- }
-
- .session-bar :global(.button) {
- padding: calc(var(--padding) / 2) var(--padding);
- font-size: 12.5px;
- }
-
- .spinning {
- animation: spin 0.6s linear infinite;
- }
-
- .courses-header {
- display: flex;
- align-items: baseline;
- gap: var(--padding);
- }
-
- .courses-header h2 {
- margin-block: 0;
- }
-
- .subtext {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .courses-grid {
- display: grid;
- grid-template-columns: repeat(4, 1fr);
- gap: var(--padding);
- }
-
- @media (max-width: 1000px) {
- .courses-grid {
- grid-template-columns: repeat(3, 1fr);
- }
- }
-
- @media (max-width: 750px) {
- .courses-grid {
- grid-template-columns: repeat(2, 1fr);
- }
- }
-
- @media (max-width: 535px) {
- .courses-grid {
- grid-template-columns: 1fr;
- }
- }
-
- .pagination {
- display: flex;
- flex-direction: column;
- align-items: center;
- gap: var(--padding);
- padding-top: var(--padding);
- }
-
- .pagination-info {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .pagination-controls {
- display: flex;
- align-items: center;
- gap: calc(var(--padding) / 3);
- }
-
- .pagination-btn {
- min-width: 36px;
- height: 36px;
- padding: 0;
- display: flex;
- align-items: center;
- justify-content: center;
- font-size: 14.5px;
- }
-
- .pagination-ellipsis {
- min-width: 36px;
- text-align: center;
- color: var(--gray);
- font-size: 14.5px;
- }
-
- .login-card {
- width: 100%;
- max-width: 400px;
- background: var(--button-elevated);
- border-radius: var(--border-radius);
- padding: calc(var(--padding) * 2);
- display: flex;
- flex-direction: column;
- gap: calc(var(--padding) * 1.5);
- }
-
- .login-card h2 {
- margin-block: 0;
- }
-
- .hidden-file-input { display: none; }
-
- .token-textarea {
- resize: vertical;
- min-height: 80px;
- font-size: 11.5px;
- font-family: var(--font-mono);
- line-height: 1.5;
- }
-
- .form {
- display: flex;
- flex-direction: column;
- gap: var(--padding);
- }
-
- .field {
- display: flex;
- flex-direction: column;
- gap: calc(var(--padding) / 2);
- }
-
- .field-label {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .input {
- width: 100%;
- padding: var(--padding);
- font-size: 14.5px;
- background: var(--button);
- border-radius: var(--border-radius);
- color: var(--secondary);
- border: 1px solid var(--input-border);
- }
-
- .input::placeholder {
- color: var(--gray);
- }
-
- .input:focus-visible {
- border-color: var(--secondary);
- outline: none;
- }
-
- .input:disabled {
- opacity: 0.5;
- cursor: default;
- }
-
- .error-msg {
- color: var(--red);
- font-size: 12.5px;
- font-weight: 500;
- }
-
- .spinner-section {
- display: flex;
- flex-direction: column;
- align-items: center;
- gap: var(--padding);
- padding: calc(var(--padding) * 4) 0;
- }
-
- .spinner {
- width: 24px;
- height: 24px;
- border: 2px solid var(--input-border);
- border-top-color: var(--blue);
- border-radius: 50%;
- animation: spin 0.6s linear infinite;
- }
-
- @keyframes spin {
- to {
- transform: rotate(360deg);
- }
- }
-
- .spinner-text {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .error-section {
- display: flex;
- flex-direction: column;
- align-items: center;
- gap: var(--padding);
- padding: calc(var(--padding) * 2) 0;
- }
-
- .empty-text {
- color: var(--gray);
- font-size: 14.5px;
- text-align: center;
- padding: calc(var(--padding) * 4) 0;
- }
-</style>
diff --git a/src/routes/courses/greatcourses/+page.svelte b/src/routes/courses/greatcourses/+page.svelte
deleted file mode 100644
index 7d9bd0c8..00000000
--- a/src/routes/courses/greatcourses/+page.svelte
+++ /dev/null
@@ -1,700 +0,0 @@
-<script lang="ts">
- import { pluginInvoke } from "$lib/plugin-invoke";
- import { open } from "@tauri-apps/plugin-dialog";
- import CourseCard from "$components/hotmart/CourseCard.svelte";
- import { showToast } from "$lib/stores/toast-store.svelte";
- import { getDownloads } from "$lib/stores/download-store.svelte";
- import { getSettings } from "$lib/stores/settings-store.svelte";
- import { t } from "$lib/i18n";
-
- let downloads = $derived(getDownloads());
-
- type WondriumCourse = {
- id: string;
- name: string;
- };
-
- let email = $state("");
- let password = $state("");
- let token = $state("");
- let fileInput: HTMLInputElement = $state() as HTMLInputElement;
- function onFileSelected(e: Event) {
- const input = e.target as HTMLInputElement;
- const file = input.files?.[0];
- if (!file) return;
- const reader = new FileReader();
- reader.onload = () => { token = reader.result as string; };
- reader.readAsText(file);
- input.value = "";
- }
- let loading = $state(false);
- let error = $state("");
-
- let checking = $state(true);
- let loggedIn = $state(false);
- let sessionEmail = $state("");
-
- let loginMode = $state<"credentials" | "token">("credentials");
-
- let courses: WondriumCourse[] = $state([]);
- let loadingCourses = $state(false);
- let coursesError = $state("");
-
- const ITEMS_PER_PAGE = 12;
- let currentPage = $state(1);
-
- let totalPages = $derived(Math.max(1, Math.ceil(courses.length / ITEMS_PER_PAGE)));
- let paginatedCourses = $derived(
- courses.slice((currentPage - 1) * ITEMS_PER_PAGE, currentPage * ITEMS_PER_PAGE)
- );
-
- let pageNumbers = $derived((): number[] => {
- const pages: number[] = [];
- if (totalPages <= 7) {
- for (let i = 1; i <= totalPages; i++) pages.push(i);
- } else {
- pages.push(1);
- if (currentPage > 3) pages.push(-1);
- const start = Math.max(2, currentPage - 1);
- const end = Math.min(totalPages - 1, currentPage + 1);
- for (let i = start; i <= end; i++) pages.push(i);
- if (currentPage < totalPages - 2) pages.push(-1);
- pages.push(totalPages);
- }
- return pages;
- });
-
- function goToPage(page: number) {
- if (page >= 1 && page <= totalPages) {
- currentPage = page;
- }
- }
-
- $effect(() => {
- checkSession();
- });
-
- async function checkSession() {
- try {
- const result = await pluginInvoke<string>("courses", "wondrium_check_session");
- sessionEmail = result;
- loggedIn = true;
- loadCourses();
- } catch {
- loggedIn = false;
- } finally {
- checking = false;
- }
- }
-
- async function handleLogin() {
- error = "";
- loading = true;
- try {
- const result = await pluginInvoke<string>("courses", "wondrium_login", { email, password });
- sessionEmail = result || email;
- loggedIn = true;
- loadCourses();
- } catch (e: any) {
- error = typeof e === "string" ? e : e.message ?? $t('hotmart.unknown_error');
- } finally {
- loading = false;
- }
- }
-
- async function handleTokenLogin() {
- if (!token.trim()) return;
- error = "";
- loading = true;
- try {
- const result = await pluginInvoke<string>("courses", "wondrium_login_token", { token: token.trim() });
- sessionEmail = result || "Token";
- loggedIn = true;
- loadCourses();
- } catch (e: any) {
- error = typeof e === "string" ? e : e.message ?? $t('hotmart.unknown_error');
- } finally {
- loading = false;
- }
- }
-
- async function handleLogout() {
- try {
- await pluginInvoke("courses", "wondrium_logout");
- } catch {
- }
- loggedIn = false;
- sessionEmail = "";
- courses = [];
- coursesError = "";
- currentPage = 1;
- }
-
- async function loadCourses() {
- loadingCourses = true;
- coursesError = "";
- try {
- courses = await pluginInvoke("courses", "wondrium_list_courses");
- currentPage = 1;
- } catch (e: any) {
- coursesError = typeof e === "string" ? e : e.message ?? $t('hotmart.courses_error');
- } finally {
- loadingCourses = false;
- }
- }
-
- function getCourseDownloadStatus(courseId: string): "idle" | "downloading" | "complete" | "error" {
- const hash = hashString(courseId);
- const item = downloads.get(hash);
- if (!item) return "idle";
- const s = item.status;
- if (s === "queued" || s === "paused" || s === "seeding") return "downloading";
- return s;
- }
-
- function getCourseDownloadPercent(courseId: string): number {
- return downloads.get(hashString(courseId))?.percent ?? 0;
- }
-
- function hashString(str: string): number {
- let hash = 0;
- for (let i = 0; i < str.length; i++) {
- const char = str.charCodeAt(i);
- hash = ((hash << 5) - hash) + char;
- hash |= 0;
- }
- return Math.abs(hash);
- }
-
- async function downloadCourse(course: WondriumCourse) {
- const status = getCourseDownloadStatus(course.id);
- if (status === "downloading") {
- showToast("info", $t("toast.download_already_active"));
- return;
- }
- if (status === "complete") return;
-
- const appSettings = getSettings();
- let outputDir: string | null = null;
-
- if (appSettings?.download.always_ask_path) {
- outputDir = await open({ directory: true, title: $t("hotmart.choose_folder") }) as string | null;
- if (!outputDir) return;
- } else {
- outputDir = appSettings?.download.default_output_dir ?? null;
- if (!outputDir) {
- outputDir = await open({ directory: true, title: $t("hotmart.choose_folder") }) as string | null;
- if (!outputDir) return;
- }
- }
-
- try {
- await pluginInvoke("courses", "start_wondrium_course_download", {
- courseJson: JSON.stringify(course),
- outputDir,
- });
- showToast("info", $t("toast.download_preparing"));
- } catch (e: any) {
- const msg = typeof e === "string" ? e : e.message ?? $t("common.error");
- showToast("error", msg);
- }
- }
-
- let refreshing = $state(false);
-
- async function refreshCourses() {
- refreshing = true;
- loadingCourses = true;
- coursesError = "";
- try {
- courses = await pluginInvoke("courses", "wondrium_refresh_courses");
- currentPage = 1;
- } catch (e: any) {
- coursesError = typeof e === "string" ? e : e.message ?? $t('hotmart.courses_error');
- } finally {
- loadingCourses = false;
- refreshing = false;
- }
- }
-</script>
-
-<a href="/courses" class="back-link">
- <svg viewBox="0 0 24 24" width="16" height="16" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
- <path d="M19 12H5" />
- <path d="M12 19l-7-7 7-7" />
- </svg>
- {$t("courses.back")}
-</a>
-
-{#if checking}
- <div class="page-center">
- <span class="spinner"></span>
- <span class="spinner-text">{$t('hotmart.checking_session')}</span>
- </div>
-{:else if loggedIn}
- <div class="page-logged">
- <div class="session-bar">
- <span class="session-info">
- {$t('hotmart.logged_as', { email: sessionEmail || "Wondrium" })}
- </span>
- <div class="session-actions">
- <button
- class="button"
- onclick={refreshCourses}
- disabled={refreshing}
- aria-label={$t('hotmart.refresh')}
- >
- <svg viewBox="0 0 24 24" width="14" height="14" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class:spinning={refreshing}>
- <path d="M21 2v6h-6" />
- <path d="M3 12a9 9 0 0115-6.7L21 8" />
- <path d="M3 22v-6h6" />
- <path d="M21 12a9 9 0 01-15 6.7L3 16" />
- </svg>
- </button>
- <button class="button" onclick={handleLogout}>{$t('hotmart.logout')}</button>
- </div>
- </div>
-
- {#if loadingCourses}
- <div class="spinner-section">
- <span class="spinner"></span>
- <span class="spinner-text">{$t('hotmart.loading_courses')}</span>
- </div>
- {:else if coursesError}
- <div class="error-section">
- <p class="error-msg">{coursesError}</p>
- <button class="button" onclick={loadCourses}>{$t('common.retry')}</button>
- </div>
- {:else if courses.length === 0}
- <p class="empty-text">{$t('hotmart.no_courses')}</p>
- {:else}
- <div class="courses-header">
- <h2>{$t('hotmart.courses_title')}</h2>
- <span class="subtext">{courses.length === 1 ? $t('hotmart.course_count_one', { count: courses.length }) : $t('hotmart.course_count', { count: courses.length })}</span>
- </div>
-
- <div class="courses-grid">
- {#each paginatedCourses as course (course.id)}
- <CourseCard
- name={course.name}
- price=""
- downloadStatus={getCourseDownloadStatus(course.id)}
- downloadPercent={getCourseDownloadPercent(course.id)}
- onDownload={() => downloadCourse(course)}
- />
- {/each}
- </div>
-
- {#if totalPages > 1}
- <div class="pagination">
- <span class="pagination-info">
- {$t('hotmart.page_of', { current: currentPage, total: totalPages })} &middot; {courses.length === 1 ? $t('hotmart.course_count_one', { count: courses.length }) : $t('hotmart.course_count', { count: courses.length })}
- </span>
- <div class="pagination-controls">
- <button
- class="button pagination-btn"
- disabled={currentPage <= 1}
- onclick={() => goToPage(currentPage - 1)}
- >
- &lt;
- </button>
-
- {#each pageNumbers() as page}
- {#if page === -1}
- <span class="pagination-ellipsis">&hellip;</span>
- {:else}
- <button
- class="button pagination-btn"
- class:active={page === currentPage}
- onclick={() => goToPage(page)}
- >
- {page}
- </button>
- {/if}
- {/each}
-
- <button
- class="button pagination-btn"
- disabled={currentPage >= totalPages}
- onclick={() => goToPage(currentPage + 1)}
- >
- &gt;
- </button>
- </div>
- </div>
- {/if}
- {/if}
- </div>
-{:else}
- <div class="page-center">
- <div class="login-card">
- <h2>Wondrium / Great Courses</h2>
-
- <div class="login-tabs">
- <button
- class="button login-tab"
- class:active={loginMode === "credentials"}
- onclick={() => { loginMode = "credentials"; error = ""; }}
- >
- Email & Password
- </button>
- <button
- class="button login-tab"
- class:active={loginMode === "token"}
- onclick={() => { loginMode = "token"; error = ""; }}
- >
- Token
- </button>
- </div>
-
- {#if loginMode === "credentials"}
- <form class="form" onsubmit={(e) => { e.preventDefault(); handleLogin(); }}>
- <label class="field">
- <span class="field-label">{$t('hotmart.email_label')}</span>
- <input
- type="email"
- placeholder={$t('hotmart.email_placeholder')}
- bind:value={email}
- class="input"
- disabled={loading}
- required
- />
- </label>
- <label class="field">
- <span class="field-label">{$t('hotmart.password_label')}</span>
- <input
- type="password"
- placeholder={$t('hotmart.password_placeholder')}
- bind:value={password}
- class="input"
- disabled={loading}
- required
- />
- </label>
-
- {#if error}
- <p class="error-msg">{error}</p>
- {/if}
-
- <button type="submit" class="button" disabled={loading}>
- {#if loading}
- {$t('hotmart.authenticating')}
- {:else}
- {$t('hotmart.login')}
- {/if}
- </button>
- </form>
- {:else}
- <div class="form">
- <label class="field">
- <span class="field-label">Cookies JSON</span>
- <textarea
- class="input token-textarea"
- placeholder="Paste cookies JSON from browser extension or a raw token"
- bind:value={token}
- disabled={loading}
- rows="4"
- ></textarea>
- </label>
- <input type="file" accept=".json,.txt" class="hidden-file-input" bind:this={fileInput} onchange={onFileSelected} />
- <button class="button" onclick={() => fileInput?.click()} disabled={loading}>Import .json file</button>
-
- {#if error}
- <p class="error-msg">{error}</p>
- {/if}
-
- <button class="button" onclick={handleTokenLogin} disabled={loading || !token.trim()}>
- {#if loading}
- {$t('hotmart.authenticating')}
- {:else}
- {$t('hotmart.login')}
- {/if}
- </button>
- </div>
- {/if}
- </div>
- </div>
-{/if}
-
-<style>
- .back-link {
- display: inline-flex;
- align-items: center;
- gap: 6px;
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- margin-bottom: var(--padding);
- }
-
- @media (hover: hover) {
- .back-link:hover {
- color: var(--secondary);
- }
- }
-
- .page-center {
- display: flex;
- flex-direction: column;
- align-items: center;
- justify-content: center;
- min-height: calc(100vh - var(--padding) * 4 - 40px);
- gap: var(--padding);
- }
-
- .page-logged {
- display: flex;
- flex-direction: column;
- align-items: center;
- gap: calc(var(--padding) * 1.5);
- padding: calc(var(--padding) * 1.5);
- width: 100%;
- }
-
- .page-logged > :global(*) {
- width: 100%;
- max-width: 1200px;
- }
-
- .session-bar {
- display: flex;
- align-items: center;
- justify-content: space-between;
- }
-
- .session-info {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .session-actions {
- display: flex;
- gap: calc(var(--padding) / 2);
- }
-
- .session-bar :global(.button) {
- padding: calc(var(--padding) / 2) var(--padding);
- font-size: 12.5px;
- }
-
- .spinning {
- animation: spin 0.6s linear infinite;
- }
-
- .courses-header {
- display: flex;
- align-items: baseline;
- gap: var(--padding);
- }
-
- .courses-header h2 {
- margin-block: 0;
- }
-
- .subtext {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .courses-grid {
- display: grid;
- grid-template-columns: repeat(4, 1fr);
- gap: var(--padding);
- }
-
- @media (max-width: 1000px) {
- .courses-grid {
- grid-template-columns: repeat(3, 1fr);
- }
- }
-
- @media (max-width: 750px) {
- .courses-grid {
- grid-template-columns: repeat(2, 1fr);
- }
- }
-
- @media (max-width: 535px) {
- .courses-grid {
- grid-template-columns: 1fr;
- }
- }
-
- .pagination {
- display: flex;
- flex-direction: column;
- align-items: center;
- gap: var(--padding);
- padding-top: var(--padding);
- }
-
- .pagination-info {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .pagination-controls {
- display: flex;
- align-items: center;
- gap: calc(var(--padding) / 3);
- }
-
- .pagination-btn {
- min-width: 36px;
- height: 36px;
- padding: 0;
- display: flex;
- align-items: center;
- justify-content: center;
- font-size: 14.5px;
- }
-
- .pagination-ellipsis {
- min-width: 36px;
- text-align: center;
- color: var(--gray);
- font-size: 14.5px;
- }
-
- .login-card {
- width: 100%;
- max-width: 400px;
- background: var(--button-elevated);
- border-radius: var(--border-radius);
- padding: calc(var(--padding) * 2);
- display: flex;
- flex-direction: column;
- gap: calc(var(--padding) * 1.5);
- }
-
- .login-card h2 {
- margin-block: 0;
- }
-
- .login-tabs {
- display: flex;
- gap: 0;
- }
-
- .login-tab {
- flex: 1;
- border-radius: 0;
- font-size: 12.5px;
- padding: calc(var(--padding) * 0.75) var(--padding);
- }
-
- .login-tab:first-child {
- border-radius: var(--border-radius) 0 0 var(--border-radius);
- }
-
- .login-tab:last-child {
- border-radius: 0 var(--border-radius) var(--border-radius) 0;
- }
-
- .hidden-file-input {
- display: none;
- }
-
- .token-textarea {
- resize: vertical;
- min-height: 80px;
- font-size: 11.5px;
- font-family: var(--font-mono);
- line-height: 1.5;
- }
-
- .form {
- display: flex;
- flex-direction: column;
- gap: var(--padding);
- }
-
- .field {
- display: flex;
- flex-direction: column;
- gap: calc(var(--padding) / 2);
- }
-
- .field-label {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .input {
- width: 100%;
- padding: var(--padding);
- font-size: 14.5px;
- background: var(--button);
- border-radius: var(--border-radius);
- color: var(--secondary);
- border: 1px solid var(--input-border);
- }
-
- .input::placeholder {
- color: var(--gray);
- }
-
- .input:focus-visible {
- border-color: var(--secondary);
- outline: none;
- }
-
- .input:disabled {
- opacity: 0.5;
- cursor: default;
- }
-
- .error-msg {
- color: var(--red);
- font-size: 12.5px;
- font-weight: 500;
- }
-
- .spinner-section {
- display: flex;
- flex-direction: column;
- align-items: center;
- gap: var(--padding);
- padding: calc(var(--padding) * 4) 0;
- }
-
- .spinner {
- width: 24px;
- height: 24px;
- border: 2px solid var(--input-border);
- border-top-color: var(--blue);
- border-radius: 50%;
- animation: spin 0.6s linear infinite;
- }
-
- @keyframes spin {
- to {
- transform: rotate(360deg);
- }
- }
-
- .spinner-text {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .error-section {
- display: flex;
- flex-direction: column;
- align-items: center;
- gap: var(--padding);
- padding: calc(var(--padding) * 2) 0;
- }
-
- .empty-text {
- color: var(--gray);
- font-size: 14.5px;
- text-align: center;
- padding: calc(var(--padding) * 4) 0;
- }
-</style>
diff --git a/src/routes/courses/greennclub/+page.svelte b/src/routes/courses/greennclub/+page.svelte
deleted file mode 100644
index b6ecaa28..00000000
--- a/src/routes/courses/greennclub/+page.svelte
+++ /dev/null
@@ -1,606 +0,0 @@
-<script lang="ts">
- import { pluginInvoke } from "$lib/plugin-invoke";
- import { open } from "@tauri-apps/plugin-dialog";
- import CourseCard from "$components/hotmart/CourseCard.svelte";
- import { showToast } from "$lib/stores/toast-store.svelte";
- import { getDownloads } from "$lib/stores/download-store.svelte";
- import { getSettings } from "$lib/stores/settings-store.svelte";
- import { t } from "$lib/i18n";
-
- let downloads = $derived(getDownloads());
-
- type GreennCourse = {
- id: number;
- name: string;
- lessons_count: number;
- };
-
- let token = $state("");
- let loading = $state(false);
- let error = $state("");
-
- let fileInput: HTMLInputElement = $state() as HTMLInputElement;
-
- function onFileSelected(e: Event) {
- const input = e.target as HTMLInputElement;
- const file = input.files?.[0];
- if (!file) return;
- const reader = new FileReader();
- reader.onload = () => { token = reader.result as string; };
- reader.readAsText(file);
- input.value = "";
- }
-
- let checking = $state(true);
- let loggedIn = $state(false);
- let sessionEmail = $state("");
-
- let courses: GreennCourse[] = $state([]);
- let loadingCourses = $state(false);
- let coursesError = $state("");
-
- const ITEMS_PER_PAGE = 12;
- let currentPage = $state(1);
-
- let totalPages = $derived(Math.max(1, Math.ceil(courses.length / ITEMS_PER_PAGE)));
- let paginatedCourses = $derived(
- courses.slice((currentPage - 1) * ITEMS_PER_PAGE, currentPage * ITEMS_PER_PAGE)
- );
-
- let pageNumbers = $derived((): number[] => {
- const pages: number[] = [];
- if (totalPages <= 7) {
- for (let i = 1; i <= totalPages; i++) pages.push(i);
- } else {
- pages.push(1);
- if (currentPage > 3) pages.push(-1);
- const start = Math.max(2, currentPage - 1);
- const end = Math.min(totalPages - 1, currentPage + 1);
- for (let i = start; i <= end; i++) pages.push(i);
- if (currentPage < totalPages - 2) pages.push(-1);
- pages.push(totalPages);
- }
- return pages;
- });
-
- function goToPage(page: number) {
- if (page >= 1 && page <= totalPages) {
- currentPage = page;
- }
- }
-
- $effect(() => {
- checkSession();
- });
-
- async function checkSession() {
- try {
- const result = await pluginInvoke<string>("courses", "greenn_check_session");
- sessionEmail = result;
- loggedIn = true;
- loadCourses();
- } catch {
- loggedIn = false;
- } finally {
- checking = false;
- }
- }
-
- async function handleTokenLogin() {
- if (!token.trim()) return;
- error = "";
- loading = true;
- try {
- const result = await pluginInvoke<string>("courses", "greenn_login_token", { token: token.trim() });
- sessionEmail = result || "Token";
- loggedIn = true;
- loadCourses();
- } catch (e: any) {
- error = typeof e === "string" ? e : e.message ?? $t('hotmart.unknown_error');
- } finally {
- loading = false;
- }
- }
-
- async function handleLogout() {
- try {
- await pluginInvoke("courses", "greenn_logout");
- } catch {
- }
- loggedIn = false;
- sessionEmail = "";
- courses = [];
- coursesError = "";
- currentPage = 1;
- }
-
- async function loadCourses() {
- loadingCourses = true;
- coursesError = "";
- try {
- courses = await pluginInvoke("courses", "greenn_list_courses");
- currentPage = 1;
- } catch (e: any) {
- coursesError = typeof e === "string" ? e : e.message ?? $t('hotmart.courses_error');
- } finally {
- loadingCourses = false;
- }
- }
-
- function getCourseDownloadStatus(courseId: number): "idle" | "downloading" | "complete" | "error" {
- const item = downloads.get(courseId);
- if (!item) return "idle";
- const s = item.status;
- if (s === "queued" || s === "paused" || s === "seeding") return "downloading";
- return s;
- }
-
- function getCourseDownloadPercent(courseId: number): number {
- return downloads.get(courseId)?.percent ?? 0;
- }
-
- async function downloadCourse(course: GreennCourse) {
- const status = getCourseDownloadStatus(course.id);
- if (status === "downloading") {
- showToast("info", $t("toast.download_already_active"));
- return;
- }
- if (status === "complete") return;
-
- const appSettings = getSettings();
- let outputDir: string | null = null;
-
- if (appSettings?.download.always_ask_path) {
- outputDir = await open({ directory: true, title: $t("hotmart.choose_folder") }) as string | null;
- if (!outputDir) return;
- } else {
- outputDir = appSettings?.download.default_output_dir ?? null;
- if (!outputDir) {
- outputDir = await open({ directory: true, title: $t("hotmart.choose_folder") }) as string | null;
- if (!outputDir) return;
- }
- }
-
- try {
- await pluginInvoke("courses", "start_greenn_course_download", {
- courseJson: JSON.stringify(course),
- outputDir,
- });
- showToast("info", $t("toast.download_preparing"));
- } catch (e: any) {
- const msg = typeof e === "string" ? e : e.message ?? $t("common.error");
- showToast("error", msg);
- }
- }
-
- let refreshing = $state(false);
-
- async function refreshCourses() {
- refreshing = true;
- loadingCourses = true;
- coursesError = "";
- try {
- courses = await pluginInvoke("courses", "greenn_refresh_courses");
- currentPage = 1;
- } catch (e: any) {
- coursesError = typeof e === "string" ? e : e.message ?? $t('hotmart.courses_error');
- } finally {
- loadingCourses = false;
- refreshing = false;
- }
- }
-</script>
-
-<a href="/courses" class="back-link">
- <svg viewBox="0 0 24 24" width="16" height="16" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
- <path d="M19 12H5" />
- <path d="M12 19l-7-7 7-7" />
- </svg>
- {$t("courses.back")}
-</a>
-
-{#if checking}
- <div class="page-center">
- <span class="spinner"></span>
- <span class="spinner-text">{$t('hotmart.checking_session')}</span>
- </div>
-{:else if loggedIn}
- <div class="page-logged">
- <div class="session-bar">
- <span class="session-info">
- {$t('hotmart.logged_as', { email: sessionEmail || "\u2014" })}
- </span>
- <div class="session-actions">
- <button
- class="button"
- onclick={refreshCourses}
- disabled={refreshing}
- aria-label={$t('hotmart.refresh')}
- >
- <svg viewBox="0 0 24 24" width="14" height="14" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class:spinning={refreshing}>
- <path d="M21 2v6h-6" />
- <path d="M3 12a9 9 0 0115-6.7L21 8" />
- <path d="M3 22v-6h6" />
- <path d="M21 12a9 9 0 01-15 6.7L3 16" />
- </svg>
- </button>
- <button class="button" onclick={handleLogout}>{$t('hotmart.logout')}</button>
- </div>
- </div>
-
- {#if loadingCourses}
- <div class="spinner-section">
- <span class="spinner"></span>
- <span class="spinner-text">{$t('hotmart.loading_courses')}</span>
- </div>
- {:else if coursesError}
- <div class="error-section">
- <p class="error-msg">{coursesError}</p>
- <button class="button" onclick={loadCourses}>{$t('common.retry')}</button>
- </div>
- {:else if courses.length === 0}
- <p class="empty-text">{$t('hotmart.no_courses')}</p>
- {:else}
- <div class="courses-header">
- <h2>{$t('hotmart.courses_title')}</h2>
- <span class="subtext">{courses.length === 1 ? $t('hotmart.course_count_one', { count: courses.length }) : $t('hotmart.course_count', { count: courses.length })}</span>
- </div>
-
- <div class="courses-grid">
- {#each paginatedCourses as course (course.id)}
- <CourseCard
- name={course.name}
- price={course.lessons_count === 1 ? "1 lesson" : `${course.lessons_count} lessons`}
- downloadStatus={getCourseDownloadStatus(course.id)}
- downloadPercent={getCourseDownloadPercent(course.id)}
- onDownload={() => downloadCourse(course)}
- />
- {/each}
- </div>
-
- {#if totalPages > 1}
- <div class="pagination">
- <span class="pagination-info">
- {$t('hotmart.page_of', { current: currentPage, total: totalPages })} &middot; {courses.length === 1 ? $t('hotmart.course_count_one', { count: courses.length }) : $t('hotmart.course_count', { count: courses.length })}
- </span>
- <div class="pagination-controls">
- <button
- class="button pagination-btn"
- disabled={currentPage <= 1}
- onclick={() => goToPage(currentPage - 1)}
- >
- &lt;
- </button>
-
- {#each pageNumbers() as page}
- {#if page === -1}
- <span class="pagination-ellipsis">&hellip;</span>
- {:else}
- <button
- class="button pagination-btn"
- class:active={page === currentPage}
- onclick={() => goToPage(page)}
- >
- {page}
- </button>
- {/if}
- {/each}
-
- <button
- class="button pagination-btn"
- disabled={currentPage >= totalPages}
- onclick={() => goToPage(currentPage + 1)}
- >
- &gt;
- </button>
- </div>
- </div>
- {/if}
- {/if}
- </div>
-{:else}
- <div class="page-center">
- <div class="login-card">
- <h2>Greenn Club</h2>
-
- <div class="form">
- <label class="field">
- <span class="field-label">Cookies JSON</span>
- <textarea
- class="input token-textarea"
- placeholder="Paste cookies JSON from browser extension or a raw token"
- bind:value={token}
- disabled={loading}
- rows="5"
- ></textarea>
- </label>
-
- <input
- type="file"
- accept=".json,.txt"
- class="hidden-file-input"
- bind:this={fileInput}
- onchange={onFileSelected}
- />
- <button class="button" onclick={() => fileInput?.click()} disabled={loading}>
- Import .json file
- </button>
-
- {#if error}
- <p class="error-msg">{error}</p>
- {/if}
-
- <button class="button" onclick={handleTokenLogin} disabled={loading || !token.trim()}>
- {#if loading}
- {$t('hotmart.authenticating')}
- {:else}
- {$t('hotmart.login')}
- {/if}
- </button>
- </div>
- </div>
- </div>
-{/if}
-
-<style>
- .back-link {
- display: inline-flex;
- align-items: center;
- gap: 6px;
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- margin-bottom: var(--padding);
- }
-
- @media (hover: hover) {
- .back-link:hover {
- color: var(--secondary);
- }
- }
-
- .page-center {
- display: flex;
- flex-direction: column;
- align-items: center;
- justify-content: center;
- min-height: calc(100vh - var(--padding) * 4 - 40px);
- gap: var(--padding);
- }
-
- .page-logged {
- display: flex;
- flex-direction: column;
- align-items: center;
- gap: calc(var(--padding) * 1.5);
- padding: calc(var(--padding) * 1.5);
- width: 100%;
- }
-
- .page-logged > :global(*) {
- width: 100%;
- max-width: 1200px;
- }
-
- .session-bar {
- display: flex;
- align-items: center;
- justify-content: space-between;
- }
-
- .session-info {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .session-actions {
- display: flex;
- gap: calc(var(--padding) / 2);
- }
-
- .session-bar :global(.button) {
- padding: calc(var(--padding) / 2) var(--padding);
- font-size: 12.5px;
- }
-
- .spinning {
- animation: spin 0.6s linear infinite;
- }
-
- .courses-header {
- display: flex;
- align-items: baseline;
- gap: var(--padding);
- }
-
- .courses-header h2 {
- margin-block: 0;
- }
-
- .subtext {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .courses-grid {
- display: grid;
- grid-template-columns: repeat(4, 1fr);
- gap: var(--padding);
- }
-
- @media (max-width: 1000px) {
- .courses-grid {
- grid-template-columns: repeat(3, 1fr);
- }
- }
-
- @media (max-width: 750px) {
- .courses-grid {
- grid-template-columns: repeat(2, 1fr);
- }
- }
-
- @media (max-width: 535px) {
- .courses-grid {
- grid-template-columns: 1fr;
- }
- }
-
- .pagination {
- display: flex;
- flex-direction: column;
- align-items: center;
- gap: var(--padding);
- padding-top: var(--padding);
- }
-
- .pagination-info {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .pagination-controls {
- display: flex;
- align-items: center;
- gap: calc(var(--padding) / 3);
- }
-
- .pagination-btn {
- min-width: 36px;
- height: 36px;
- padding: 0;
- display: flex;
- align-items: center;
- justify-content: center;
- font-size: 14.5px;
- }
-
- .pagination-ellipsis {
- min-width: 36px;
- text-align: center;
- color: var(--gray);
- font-size: 14.5px;
- }
-
- .login-card {
- width: 100%;
- max-width: 400px;
- background: var(--button-elevated);
- border-radius: var(--border-radius);
- padding: calc(var(--padding) * 2);
- display: flex;
- flex-direction: column;
- gap: calc(var(--padding) * 1.5);
- }
-
- .login-card h2 {
- margin-block: 0;
- }
-
- .hidden-file-input {
- display: none;
- }
-
- .token-textarea {
- resize: vertical;
- min-height: 80px;
- font-size: 11.5px;
- font-family: var(--font-mono);
- line-height: 1.5;
- }
-
- .form {
- display: flex;
- flex-direction: column;
- gap: var(--padding);
- }
-
- .field {
- display: flex;
- flex-direction: column;
- gap: calc(var(--padding) / 2);
- }
-
- .field-label {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .input {
- width: 100%;
- padding: var(--padding);
- font-size: 14.5px;
- background: var(--button);
- border-radius: var(--border-radius);
- color: var(--secondary);
- border: 1px solid var(--input-border);
- }
-
- .input::placeholder {
- color: var(--gray);
- }
-
- .input:focus-visible {
- border-color: var(--secondary);
- outline: none;
- }
-
- .input:disabled {
- opacity: 0.5;
- cursor: default;
- }
-
- .error-msg {
- color: var(--red);
- font-size: 12.5px;
- font-weight: 500;
- }
-
- .spinner-section {
- display: flex;
- flex-direction: column;
- align-items: center;
- gap: var(--padding);
- padding: calc(var(--padding) * 4) 0;
- }
-
- .spinner {
- width: 24px;
- height: 24px;
- border: 2px solid var(--input-border);
- border-top-color: var(--blue);
- border-radius: 50%;
- animation: spin 0.6s linear infinite;
- }
-
- @keyframes spin {
- to {
- transform: rotate(360deg);
- }
- }
-
- .spinner-text {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .error-section {
- display: flex;
- flex-direction: column;
- align-items: center;
- gap: var(--padding);
- padding: calc(var(--padding) * 2) 0;
- }
-
- .empty-text {
- color: var(--gray);
- font-size: 14.5px;
- text-align: center;
- padding: calc(var(--padding) * 4) 0;
- }
-</style>
diff --git a/src/routes/courses/gumroad/+page.svelte b/src/routes/courses/gumroad/+page.svelte
deleted file mode 100644
index 9171320a..00000000
--- a/src/routes/courses/gumroad/+page.svelte
+++ /dev/null
@@ -1,704 +0,0 @@
-<script lang="ts">
- import { pluginInvoke } from "$lib/plugin-invoke";
- import { open } from "@tauri-apps/plugin-dialog";
- import CourseCard from "$components/hotmart/CourseCard.svelte";
- import { showToast } from "$lib/stores/toast-store.svelte";
- import { getDownloads } from "$lib/stores/download-store.svelte";
- import { getSettings } from "$lib/stores/settings-store.svelte";
- import { t } from "$lib/i18n";
-
- let downloads = $derived(getDownloads());
-
- type GumroadProduct = {
- id: string;
- name: string;
- creator_name: string;
- preview_url: string | null;
- file_count: number;
- };
-
- let email = $state("");
- let password = $state("");
- let token = $state("");
- let loading = $state(false);
- let error = $state("");
-
- let checking = $state(true);
- let loggedIn = $state(false);
- let sessionEmail = $state("");
-
- let loginMode = $state<"credentials" | "token">("credentials");
-
- let fileInput: HTMLInputElement = $state() as HTMLInputElement;
-
- function onFileSelected(e: Event) {
- const input = e.target as HTMLInputElement;
- const file = input.files?.[0];
- if (!file) return;
- const reader = new FileReader();
- reader.onload = () => { token = reader.result as string; };
- reader.readAsText(file);
- input.value = "";
- }
-
- let courses: GumroadProduct[] = $state([]);
- let loadingCourses = $state(false);
- let coursesError = $state("");
-
- const ITEMS_PER_PAGE = 12;
- let currentPage = $state(1);
-
- let totalPages = $derived(Math.max(1, Math.ceil(courses.length / ITEMS_PER_PAGE)));
- let paginatedCourses = $derived(
- courses.slice((currentPage - 1) * ITEMS_PER_PAGE, currentPage * ITEMS_PER_PAGE)
- );
-
- let pageNumbers = $derived((): number[] => {
- const pages: number[] = [];
- if (totalPages <= 7) {
- for (let i = 1; i <= totalPages; i++) pages.push(i);
- } else {
- pages.push(1);
- if (currentPage > 3) pages.push(-1);
- const start = Math.max(2, currentPage - 1);
- const end = Math.min(totalPages - 1, currentPage + 1);
- for (let i = start; i <= end; i++) pages.push(i);
- if (currentPage < totalPages - 2) pages.push(-1);
- pages.push(totalPages);
- }
- return pages;
- });
-
- function goToPage(page: number) {
- if (page >= 1 && page <= totalPages) {
- currentPage = page;
- }
- }
-
- $effect(() => {
- checkSession();
- });
-
- async function checkSession() {
- try {
- const result = await pluginInvoke<string>("courses", "gumroad_check_session");
- sessionEmail = result;
- loggedIn = true;
- loadCourses();
- } catch {
- loggedIn = false;
- } finally {
- checking = false;
- }
- }
-
- async function handleLogin() {
- error = "";
- loading = true;
- try {
- const result = await pluginInvoke<string>("courses", "gumroad_login", { email, password });
- sessionEmail = result || email;
- loggedIn = true;
- loadCourses();
- } catch (e: any) {
- error = typeof e === "string" ? e : e.message ?? $t('hotmart.unknown_error');
- } finally {
- loading = false;
- }
- }
-
- async function handleTokenLogin() {
- if (!token.trim()) return;
- error = "";
- loading = true;
- try {
- const result = await pluginInvoke<string>("courses", "gumroad_login_token", { token: token.trim() });
- sessionEmail = result || "Token";
- loggedIn = true;
- loadCourses();
- } catch (e: any) {
- error = typeof e === "string" ? e : e.message ?? $t('hotmart.unknown_error');
- } finally {
- loading = false;
- }
- }
-
- async function handleLogout() {
- try {
- await pluginInvoke("courses", "gumroad_logout");
- } catch {
- }
- loggedIn = false;
- sessionEmail = "";
- courses = [];
- coursesError = "";
- currentPage = 1;
- }
-
- async function loadCourses() {
- loadingCourses = true;
- coursesError = "";
- try {
- courses = await pluginInvoke("courses", "gumroad_list_products");
- currentPage = 1;
- } catch (e: any) {
- coursesError = typeof e === "string" ? e : e.message ?? $t('hotmart.courses_error');
- } finally {
- loadingCourses = false;
- }
- }
-
- function getCourseDownloadStatus(courseId: number): "idle" | "downloading" | "complete" | "error" {
- const item = downloads.get(courseId);
- if (!item) return "idle";
- const s = item.status;
- if (s === "queued" || s === "paused" || s === "seeding") return "downloading";
- return s;
- }
-
- function getCourseDownloadPercent(courseId: number): number {
- return downloads.get(courseId)?.percent ?? 0;
- }
-
- async function downloadCourse(product: GumroadProduct) {
- const status = getCourseDownloadStatus(Number(product.id) || 0);
- if (status === "downloading") {
- showToast("info", $t("toast.download_already_active"));
- return;
- }
- if (status === "complete") return;
-
- const appSettings = getSettings();
- let outputDir: string | null = null;
-
- if (appSettings?.download.always_ask_path) {
- outputDir = await open({ directory: true, title: $t("hotmart.choose_folder") }) as string | null;
- if (!outputDir) return;
- } else {
- outputDir = appSettings?.download.default_output_dir ?? null;
- if (!outputDir) {
- outputDir = await open({ directory: true, title: $t("hotmart.choose_folder") }) as string | null;
- if (!outputDir) return;
- }
- }
-
- try {
- await pluginInvoke("courses", "start_gumroad_download", {
- productJson: JSON.stringify(product),
- outputDir,
- });
- showToast("info", $t("toast.download_preparing"));
- } catch (e: any) {
- const msg = typeof e === "string" ? e : e.message ?? $t("common.error");
- showToast("error", msg);
- }
- }
-
- let refreshing = $state(false);
-
- async function refreshCourses() {
- refreshing = true;
- loadingCourses = true;
- coursesError = "";
- try {
- courses = await pluginInvoke("courses", "gumroad_refresh_products");
- currentPage = 1;
- } catch (e: any) {
- coursesError = typeof e === "string" ? e : e.message ?? $t('hotmart.courses_error');
- } finally {
- loadingCourses = false;
- refreshing = false;
- }
- }
-</script>
-
-<a href="/courses" class="back-link">
- <svg viewBox="0 0 24 24" width="16" height="16" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
- <path d="M19 12H5" />
- <path d="M12 19l-7-7 7-7" />
- </svg>
- {$t("courses.back")}
-</a>
-
-{#if checking}
- <div class="page-center">
- <span class="spinner"></span>
- <span class="spinner-text">{$t('hotmart.checking_session')}</span>
- </div>
-{:else if loggedIn}
- <div class="page-logged">
- <div class="session-bar">
- <span class="session-info">
- {$t('hotmart.logged_as', { email: sessionEmail || "—" })}
- </span>
- <div class="session-actions">
- <button
- class="button"
- onclick={refreshCourses}
- disabled={refreshing}
- aria-label={$t('hotmart.refresh')}
- >
- <svg viewBox="0 0 24 24" width="14" height="14" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class:spinning={refreshing}>
- <path d="M21 2v6h-6" />
- <path d="M3 12a9 9 0 0115-6.7L21 8" />
- <path d="M3 22v-6h6" />
- <path d="M21 12a9 9 0 01-15 6.7L3 16" />
- </svg>
- </button>
- <button class="button" onclick={handleLogout}>{$t('hotmart.logout')}</button>
- </div>
- </div>
-
- {#if loadingCourses}
- <div class="spinner-section">
- <span class="spinner"></span>
- <span class="spinner-text">{$t('hotmart.loading_courses')}</span>
- </div>
- {:else if coursesError}
- <div class="error-section">
- <p class="error-msg">{coursesError}</p>
- <button class="button" onclick={loadCourses}>{$t('common.retry')}</button>
- </div>
- {:else if courses.length === 0}
- <p class="empty-text">{$t('hotmart.no_courses')}</p>
- {:else}
- <div class="courses-header">
- <h2>{$t('hotmart.courses_title')}</h2>
- <span class="subtext">{courses.length === 1 ? $t('hotmart.course_count_one', { count: courses.length }) : $t('hotmart.course_count', { count: courses.length })}</span>
- </div>
-
- <div class="courses-grid">
- {#each paginatedCourses as product (product.id)}
- <CourseCard
- name={product.name}
- price={product.creator_name}
- imageUrl={product.preview_url ?? undefined}
- downloadStatus={getCourseDownloadStatus(Number(product.id) || 0)}
- downloadPercent={getCourseDownloadPercent(Number(product.id) || 0)}
- onDownload={() => downloadCourse(product)}
- />
- {/each}
- </div>
-
- {#if totalPages > 1}
- <div class="pagination">
- <span class="pagination-info">
- {$t('hotmart.page_of', { current: currentPage, total: totalPages })} &middot; {courses.length === 1 ? $t('hotmart.course_count_one', { count: courses.length }) : $t('hotmart.course_count', { count: courses.length })}
- </span>
- <div class="pagination-controls">
- <button
- class="button pagination-btn"
- disabled={currentPage <= 1}
- onclick={() => goToPage(currentPage - 1)}
- >
- &lt;
- </button>
-
- {#each pageNumbers() as page}
- {#if page === -1}
- <span class="pagination-ellipsis">&hellip;</span>
- {:else}
- <button
- class="button pagination-btn"
- class:active={page === currentPage}
- onclick={() => goToPage(page)}
- >
- {page}
- </button>
- {/if}
- {/each}
-
- <button
- class="button pagination-btn"
- disabled={currentPage >= totalPages}
- onclick={() => goToPage(currentPage + 1)}
- >
- &gt;
- </button>
- </div>
- </div>
- {/if}
- {/if}
- </div>
-{:else}
- <div class="page-center">
- <div class="login-card">
- <h2>Gumroad</h2>
-
- <div class="login-tabs">
- <button
- class="button login-tab"
- class:active={loginMode === "credentials"}
- onclick={() => { loginMode = "credentials"; error = ""; }}
- >
- Email & Password
- </button>
- <button
- class="button login-tab"
- class:active={loginMode === "token"}
- onclick={() => { loginMode = "token"; error = ""; }}
- >
- Token
- </button>
- </div>
-
- {#if loginMode === "credentials"}
- <form class="form" onsubmit={(e) => { e.preventDefault(); handleLogin(); }}>
- <label class="field">
- <span class="field-label">{$t('hotmart.email_label')}</span>
- <input
- type="email"
- placeholder={$t('hotmart.email_placeholder')}
- bind:value={email}
- class="input"
- disabled={loading}
- required
- />
- </label>
- <label class="field">
- <span class="field-label">{$t('hotmart.password_label')}</span>
- <input
- type="password"
- placeholder={$t('hotmart.password_placeholder')}
- bind:value={password}
- class="input"
- disabled={loading}
- required
- />
- </label>
-
- {#if error}
- <p class="error-msg">{error}</p>
- {/if}
-
- <button type="submit" class="button" disabled={loading}>
- {#if loading}
- {$t('hotmart.authenticating')}
- {:else}
- {$t('hotmart.login')}
- {/if}
- </button>
- </form>
- {:else}
- <div class="form">
- <label class="field">
- <span class="field-label">Cookies JSON</span>
- <textarea
- class="input token-textarea"
- placeholder="Paste cookies JSON from browser extension or a raw token"
- bind:value={token}
- disabled={loading}
- rows="5"
- ></textarea>
- </label>
-
- <input
- type="file"
- accept=".json,.txt"
- class="hidden-file-input"
- bind:this={fileInput}
- onchange={onFileSelected}
- />
- <button class="button" onclick={() => fileInput?.click()} disabled={loading}>
- Import .json file
- </button>
-
- {#if error}
- <p class="error-msg">{error}</p>
- {/if}
-
- <button class="button" onclick={handleTokenLogin} disabled={loading || !token.trim()}>
- {#if loading}
- {$t('hotmart.authenticating')}
- {:else}
- {$t('hotmart.login')}
- {/if}
- </button>
- </div>
- {/if}
- </div>
- </div>
-{/if}
-
-<style>
- .back-link {
- display: inline-flex;
- align-items: center;
- gap: 6px;
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- margin-bottom: var(--padding);
- }
-
- @media (hover: hover) {
- .back-link:hover {
- color: var(--secondary);
- }
- }
-
- .page-center {
- display: flex;
- flex-direction: column;
- align-items: center;
- justify-content: center;
- min-height: calc(100vh - var(--padding) * 4 - 40px);
- gap: var(--padding);
- }
-
- .page-logged {
- display: flex;
- flex-direction: column;
- align-items: center;
- gap: calc(var(--padding) * 1.5);
- padding: calc(var(--padding) * 1.5);
- width: 100%;
- }
-
- .page-logged > :global(*) {
- width: 100%;
- max-width: 1200px;
- }
-
- .session-bar {
- display: flex;
- align-items: center;
- justify-content: space-between;
- }
-
- .session-info {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .session-actions {
- display: flex;
- gap: calc(var(--padding) / 2);
- }
-
- .session-bar :global(.button) {
- padding: calc(var(--padding) / 2) var(--padding);
- font-size: 12.5px;
- }
-
- .spinning {
- animation: spin 0.6s linear infinite;
- }
-
- .courses-header {
- display: flex;
- align-items: baseline;
- gap: var(--padding);
- }
-
- .courses-header h2 {
- margin-block: 0;
- }
-
- .subtext {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .courses-grid {
- display: grid;
- grid-template-columns: repeat(4, 1fr);
- gap: var(--padding);
- }
-
- @media (max-width: 1000px) {
- .courses-grid {
- grid-template-columns: repeat(3, 1fr);
- }
- }
-
- @media (max-width: 750px) {
- .courses-grid {
- grid-template-columns: repeat(2, 1fr);
- }
- }
-
- @media (max-width: 535px) {
- .courses-grid {
- grid-template-columns: 1fr;
- }
- }
-
- .pagination {
- display: flex;
- flex-direction: column;
- align-items: center;
- gap: var(--padding);
- padding-top: var(--padding);
- }
-
- .pagination-info {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .pagination-controls {
- display: flex;
- align-items: center;
- gap: calc(var(--padding) / 3);
- }
-
- .pagination-btn {
- min-width: 36px;
- height: 36px;
- padding: 0;
- display: flex;
- align-items: center;
- justify-content: center;
- font-size: 14.5px;
- }
-
- .pagination-ellipsis {
- min-width: 36px;
- text-align: center;
- color: var(--gray);
- font-size: 14.5px;
- }
-
- .login-card {
- width: 100%;
- max-width: 400px;
- background: var(--button-elevated);
- border-radius: var(--border-radius);
- padding: calc(var(--padding) * 2);
- display: flex;
- flex-direction: column;
- gap: calc(var(--padding) * 1.5);
- }
-
- .login-card h2 {
- margin-block: 0;
- }
-
- .login-tabs {
- display: flex;
- gap: 0;
- }
-
- .login-tab {
- flex: 1;
- border-radius: 0;
- font-size: 12.5px;
- padding: calc(var(--padding) * 0.75) var(--padding);
- }
-
- .login-tab:first-child {
- border-radius: var(--border-radius) 0 0 var(--border-radius);
- }
-
- .login-tab:last-child {
- border-radius: 0 var(--border-radius) var(--border-radius) 0;
- }
-
- .hidden-file-input {
- display: none;
- }
-
- .token-textarea {
- resize: vertical;
- min-height: 80px;
- font-size: 11.5px;
- font-family: var(--font-mono);
- line-height: 1.5;
- }
-
- .form {
- display: flex;
- flex-direction: column;
- gap: var(--padding);
- }
-
- .field {
- display: flex;
- flex-direction: column;
- gap: calc(var(--padding) / 2);
- }
-
- .field-label {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .input {
- width: 100%;
- padding: var(--padding);
- font-size: 14.5px;
- background: var(--button);
- border-radius: var(--border-radius);
- color: var(--secondary);
- border: 1px solid var(--input-border);
- }
-
- .input::placeholder {
- color: var(--gray);
- }
-
- .input:focus-visible {
- border-color: var(--secondary);
- outline: none;
- }
-
- .input:disabled {
- opacity: 0.5;
- cursor: default;
- }
-
- .error-msg {
- color: var(--red);
- font-size: 12.5px;
- font-weight: 500;
- }
-
- .spinner-section {
- display: flex;
- flex-direction: column;
- align-items: center;
- gap: var(--padding);
- padding: calc(var(--padding) * 4) 0;
- }
-
- .spinner {
- width: 24px;
- height: 24px;
- border: 2px solid var(--input-border);
- border-top-color: var(--blue);
- border-radius: 50%;
- animation: spin 0.6s linear infinite;
- }
-
- @keyframes spin {
- to {
- transform: rotate(360deg);
- }
- }
-
- .spinner-text {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .error-section {
- display: flex;
- flex-direction: column;
- align-items: center;
- gap: var(--padding);
- padding: calc(var(--padding) * 2) 0;
- }
-
- .empty-text {
- color: var(--gray);
- font-size: 14.5px;
- text-align: center;
- padding: calc(var(--padding) * 4) 0;
- }
-</style>
diff --git a/src/routes/courses/hotmart/+page.svelte b/src/routes/courses/hotmart/+page.svelte
deleted file mode 100644
index 5e90282d..00000000
--- a/src/routes/courses/hotmart/+page.svelte
+++ /dev/null
@@ -1,614 +0,0 @@
-<script lang="ts">
- import { pluginInvoke } from "$lib/plugin-invoke";
- import { listen } from "@tauri-apps/api/event";
- import { open } from "@tauri-apps/plugin-dialog";
- import CourseCard from "$components/hotmart/CourseCard.svelte";
- import { showToast } from "$lib/stores/toast-store.svelte";
- import { getDownloads } from "$lib/stores/download-store.svelte";
- import { getSettings } from "$lib/stores/settings-store.svelte";
- import { t } from "$lib/i18n";
-
- let downloads = $derived(getDownloads());
-
- type Course = {
- id: number;
- name: string;
- slug: string | null;
- seller: string;
- subdomain: string | null;
- is_hotmart_club: boolean;
- price: number | null;
- image_url: string | null;
- category: string | null;
- external_platform: boolean;
- };
-
- let email = $state("");
- let password = $state("");
- let loading = $state(false);
- let error = $state("");
- let captchaWarning = $state(false);
-
- let checking = $state(true);
- let loggedIn = $state(false);
- let sessionEmail = $state("");
-
- let courses: Course[] = $state([]);
- let loadingCourses = $state(false);
- let coursesError = $state("");
-
- const ITEMS_PER_PAGE = 12;
- let currentPage = $state(1);
-
- let totalPages = $derived(Math.max(1, Math.ceil(courses.length / ITEMS_PER_PAGE)));
- let paginatedCourses = $derived(
- courses.slice((currentPage - 1) * ITEMS_PER_PAGE, currentPage * ITEMS_PER_PAGE)
- );
-
- let pageNumbers = $derived((): number[] => {
- const pages: number[] = [];
- if (totalPages <= 7) {
- for (let i = 1; i <= totalPages; i++) pages.push(i);
- } else {
- pages.push(1);
- if (currentPage > 3) pages.push(-1);
- const start = Math.max(2, currentPage - 1);
- const end = Math.min(totalPages - 1, currentPage + 1);
- for (let i = start; i <= end; i++) pages.push(i);
- if (currentPage < totalPages - 2) pages.push(-1);
- pages.push(totalPages);
- }
- return pages;
- });
-
- function formatPrice(price: number | null): string {
- if (price === null || price === undefined) return "—";
- if (price === 0) return $t('hotmart.free');
- return `R$ ${price.toFixed(2).replace(".", ",")}`;
- }
-
- function goToPage(page: number) {
- if (page >= 1 && page <= totalPages) {
- currentPage = page;
- }
- }
-
- $effect(() => {
- checkSession();
- const unlisten = listen("hotmart-auth-captcha", () => {
- captchaWarning = true;
- });
- return () => { unlisten.then((fn) => fn()); };
- });
-
- async function checkSession() {
- try {
- const result = await pluginInvoke<string>("courses", "hotmart_check_session");
- sessionEmail = result;
- loggedIn = true;
- loadCourses();
- } catch {
- loggedIn = false;
- } finally {
- checking = false;
- }
- }
-
- async function handleLogin() {
- error = "";
- captchaWarning = false;
- loading = true;
- try {
- const result = await pluginInvoke<string>("courses", "hotmart_login", { email, password });
- sessionEmail = result || email;
- loggedIn = true;
- loadCourses();
- } catch (e: any) {
- error = typeof e === "string" ? e : e.message ?? $t('hotmart.unknown_error');
- } finally {
- loading = false;
- }
- }
-
- async function handleLogout() {
- try {
- await pluginInvoke("courses", "hotmart_logout");
- } catch {
- }
- loggedIn = false;
- sessionEmail = "";
- courses = [];
- coursesError = "";
- currentPage = 1;
- }
-
- async function loadCourses() {
- loadingCourses = true;
- coursesError = "";
- try {
- courses = await pluginInvoke("courses", "hotmart_list_courses");
- currentPage = 1;
- } catch (e: any) {
- coursesError = typeof e === "string" ? e : e.message ?? $t('hotmart.courses_error');
- } finally {
- loadingCourses = false;
- }
- }
-
- function getCourseDownloadStatus(courseId: number): "idle" | "downloading" | "complete" | "error" {
- const item = downloads.get(courseId);
- if (!item) return "idle";
- const s = item.status;
- if (s === "queued" || s === "paused" || s === "seeding") return "downloading";
- return s;
- }
-
- function getCourseDownloadPercent(courseId: number): number {
- return downloads.get(courseId)?.percent ?? 0;
- }
-
- async function downloadCourse(course: Course) {
- const status = getCourseDownloadStatus(course.id);
- if (status === "downloading") {
- showToast("info", $t("toast.download_already_active"));
- return;
- }
- if (status === "complete") return;
-
- const appSettings = getSettings();
- let outputDir: string | null = null;
-
- if (appSettings?.download.always_ask_path) {
- outputDir = await open({ directory: true, title: $t("hotmart.choose_folder") }) as string | null;
- if (!outputDir) return;
- } else {
- outputDir = appSettings?.download.default_output_dir ?? null;
- if (!outputDir) {
- outputDir = await open({ directory: true, title: $t("hotmart.choose_folder") }) as string | null;
- if (!outputDir) return;
- }
- }
-
- try {
- await pluginInvoke("courses", "start_course_download", {
- courseJson: JSON.stringify(course),
- outputDir,
- });
- showToast("info", $t("toast.download_preparing"));
- } catch (e: any) {
- const msg = typeof e === "string" ? e : e.message ?? $t("common.error");
- showToast("error", msg);
- }
- }
-
- let refreshing = $state(false);
-
- async function refreshCourses() {
- refreshing = true;
- loadingCourses = true;
- coursesError = "";
- try {
- courses = await pluginInvoke("courses", "hotmart_refresh_courses");
- currentPage = 1;
- } catch (e: any) {
- coursesError = typeof e === "string" ? e : e.message ?? $t('hotmart.courses_error');
- } finally {
- loadingCourses = false;
- refreshing = false;
- }
- }
-</script>
-
-<a href="/courses" class="back-link">
- <svg viewBox="0 0 24 24" width="16" height="16" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
- <path d="M19 12H5" />
- <path d="M12 19l-7-7 7-7" />
- </svg>
- {$t("courses.back")}
-</a>
-
-{#if checking}
- <div class="page-center">
- <span class="spinner"></span>
- <span class="spinner-text">{$t('hotmart.checking_session')}</span>
- </div>
-{:else if loggedIn}
- <div class="page-logged">
- <div class="session-bar">
- <span class="session-info">
- {$t('hotmart.logged_as', { email: sessionEmail || "—" })}
- </span>
- <div class="session-actions">
- <button
- class="button"
- onclick={refreshCourses}
- disabled={refreshing}
- aria-label={$t('hotmart.refresh')}
- >
- <svg viewBox="0 0 24 24" width="14" height="14" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class:spinning={refreshing}>
- <path d="M21 2v6h-6" />
- <path d="M3 12a9 9 0 0115-6.7L21 8" />
- <path d="M3 22v-6h6" />
- <path d="M21 12a9 9 0 01-15 6.7L3 16" />
- </svg>
- </button>
- <button class="button" onclick={handleLogout}>{$t('hotmart.logout')}</button>
- </div>
- </div>
-
- {#if loadingCourses}
- <div class="spinner-section">
- <span class="spinner"></span>
- <span class="spinner-text">{$t('hotmart.loading_courses')}</span>
- </div>
- {:else if coursesError}
- <div class="error-section">
- <p class="error-msg">{coursesError}</p>
- <button class="button" onclick={loadCourses}>{$t('common.retry')}</button>
- </div>
- {:else if courses.length === 0}
- <p class="empty-text">{$t('hotmart.no_courses')}</p>
- {:else}
- <div class="courses-header">
- <h2>{$t('hotmart.courses_title')}</h2>
- <span class="subtext">{courses.length === 1 ? $t('hotmart.course_count_one', { count: courses.length }) : $t('hotmart.course_count', { count: courses.length })}</span>
- </div>
-
- <div class="courses-grid">
- {#each paginatedCourses as course (course.id)}
- <CourseCard
- name={course.name}
- price={formatPrice(course.price)}
- imageUrl={course.image_url ?? undefined}
- externalPlatform={course.external_platform}
- downloadStatus={getCourseDownloadStatus(course.id)}
- downloadPercent={getCourseDownloadPercent(course.id)}
- onDownload={() => downloadCourse(course)}
- />
- {/each}
- </div>
-
- {#if totalPages > 1}
- <div class="pagination">
- <span class="pagination-info">
- {$t('hotmart.page_of', { current: currentPage, total: totalPages })} &middot; {courses.length === 1 ? $t('hotmart.course_count_one', { count: courses.length }) : $t('hotmart.course_count', { count: courses.length })}
- </span>
- <div class="pagination-controls">
- <button
- class="button pagination-btn"
- disabled={currentPage <= 1}
- onclick={() => goToPage(currentPage - 1)}
- >
- &lt;
- </button>
-
- {#each pageNumbers() as page}
- {#if page === -1}
- <span class="pagination-ellipsis">&hellip;</span>
- {:else}
- <button
- class="button pagination-btn"
- class:active={page === currentPage}
- onclick={() => goToPage(page)}
- >
- {page}
- </button>
- {/if}
- {/each}
-
- <button
- class="button pagination-btn"
- disabled={currentPage >= totalPages}
- onclick={() => goToPage(currentPage + 1)}
- >
- &gt;
- </button>
- </div>
- </div>
- {/if}
- {/if}
- </div>
-{:else}
- <div class="page-center">
- <div class="login-card">
- <h2>{$t('hotmart.title')}</h2>
- <form class="form" onsubmit={(e) => { e.preventDefault(); handleLogin(); }}>
- <label class="field">
- <span class="field-label">{$t('hotmart.email_label')}</span>
- <input
- type="email"
- placeholder={$t('hotmart.email_placeholder')}
- bind:value={email}
- class="input"
- disabled={loading}
- required
- />
- </label>
- <label class="field">
- <span class="field-label">{$t('hotmart.password_label')}</span>
- <input
- type="password"
- placeholder={$t('hotmart.password_placeholder')}
- bind:value={password}
- class="input"
- disabled={loading}
- required
- />
- </label>
-
- {#if error}
- <p class="error-msg">{error}</p>
- {/if}
-
- {#if captchaWarning}
- <p class="captcha-warning">{$t('hotmart.captcha_detected')}</p>
- {/if}
-
- <button type="submit" class="button" disabled={loading}>
- {#if loading}
- {$t('hotmart.authenticating')}
- {:else}
- {$t('hotmart.login')}
- {/if}
- </button>
- </form>
- </div>
- </div>
-{/if}
-
-<style>
- .back-link {
- display: inline-flex;
- align-items: center;
- gap: 6px;
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- margin-bottom: var(--padding);
- }
-
- @media (hover: hover) {
- .back-link:hover {
- color: var(--secondary);
- }
- }
-
- .page-center {
- display: flex;
- flex-direction: column;
- align-items: center;
- justify-content: center;
- min-height: calc(100vh - var(--padding) * 4 - 40px);
- gap: var(--padding);
- }
-
- .page-logged {
- display: flex;
- flex-direction: column;
- align-items: center;
- gap: calc(var(--padding) * 1.5);
- padding: calc(var(--padding) * 1.5);
- width: 100%;
- }
-
- .page-logged > :global(*) {
- width: 100%;
- max-width: 1200px;
- }
-
- .session-bar {
- display: flex;
- align-items: center;
- justify-content: space-between;
- }
-
- .session-info {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .session-actions {
- display: flex;
- gap: calc(var(--padding) / 2);
- }
-
- .session-bar :global(.button) {
- padding: calc(var(--padding) / 2) var(--padding);
- font-size: 12.5px;
- }
-
- .spinning {
- animation: spin 0.6s linear infinite;
- }
-
- .courses-header {
- display: flex;
- align-items: baseline;
- gap: var(--padding);
- }
-
- .courses-header h2 {
- margin-block: 0;
- }
-
- .subtext {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .courses-grid {
- display: grid;
- grid-template-columns: repeat(4, 1fr);
- gap: var(--padding);
- }
-
- @media (max-width: 1000px) {
- .courses-grid {
- grid-template-columns: repeat(3, 1fr);
- }
- }
-
- @media (max-width: 750px) {
- .courses-grid {
- grid-template-columns: repeat(2, 1fr);
- }
- }
-
- @media (max-width: 535px) {
- .courses-grid {
- grid-template-columns: 1fr;
- }
- }
-
- .pagination {
- display: flex;
- flex-direction: column;
- align-items: center;
- gap: var(--padding);
- padding-top: var(--padding);
- }
-
- .pagination-info {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .pagination-controls {
- display: flex;
- align-items: center;
- gap: calc(var(--padding) / 3);
- }
-
- .pagination-btn {
- min-width: 36px;
- height: 36px;
- padding: 0;
- display: flex;
- align-items: center;
- justify-content: center;
- font-size: 14.5px;
- }
-
- .pagination-ellipsis {
- min-width: 36px;
- text-align: center;
- color: var(--gray);
- font-size: 14.5px;
- }
-
- .login-card {
- width: 100%;
- max-width: 400px;
- background: var(--button-elevated);
- border-radius: var(--border-radius);
- padding: calc(var(--padding) * 2);
- display: flex;
- flex-direction: column;
- gap: calc(var(--padding) * 1.5);
- }
-
- .login-card h2 {
- margin-block: 0;
- }
-
- .form {
- display: flex;
- flex-direction: column;
- gap: var(--padding);
- }
-
- .field {
- display: flex;
- flex-direction: column;
- gap: calc(var(--padding) / 2);
- }
-
- .field-label {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .input {
- width: 100%;
- padding: var(--padding);
- font-size: 14.5px;
- background: var(--button);
- border-radius: var(--border-radius);
- color: var(--secondary);
- border: 1px solid var(--input-border);
- }
-
- .input::placeholder {
- color: var(--gray);
- }
-
- .input:focus-visible {
- border-color: var(--secondary);
- outline: none;
- }
-
- .input:disabled {
- opacity: 0.5;
- cursor: default;
- }
-
- .error-msg {
- color: var(--red);
- font-size: 12.5px;
- font-weight: 500;
- }
-
- .captcha-warning {
- color: var(--orange);
- font-size: 12.5px;
- font-weight: 500;
- }
-
- .spinner-section {
- display: flex;
- flex-direction: column;
- align-items: center;
- gap: var(--padding);
- padding: calc(var(--padding) * 4) 0;
- }
-
- .spinner {
- width: 24px;
- height: 24px;
- border: 2px solid var(--input-border);
- border-top-color: var(--blue);
- border-radius: 50%;
- animation: spin 0.6s linear infinite;
- }
-
- @keyframes spin {
- to {
- transform: rotate(360deg);
- }
- }
-
- .spinner-text {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .error-section {
- display: flex;
- flex-direction: column;
- align-items: center;
- gap: var(--padding);
- padding: calc(var(--padding) * 2) 0;
- }
-
- .empty-text {
- color: var(--gray);
- font-size: 14.5px;
- text-align: center;
- padding: calc(var(--padding) * 4) 0;
- }
-</style>
diff --git a/src/routes/courses/kajabi/+page.svelte b/src/routes/courses/kajabi/+page.svelte
deleted file mode 100644
index 78901dfd..00000000
--- a/src/routes/courses/kajabi/+page.svelte
+++ /dev/null
@@ -1,597 +0,0 @@
-<script lang="ts">
- import { pluginInvoke } from "$lib/plugin-invoke";
- import { open } from "@tauri-apps/plugin-dialog";
- import CourseCard from "$components/hotmart/CourseCard.svelte";
- import { showToast } from "$lib/stores/toast-store.svelte";
- import { getDownloads } from "$lib/stores/download-store.svelte";
- import { getSettings } from "$lib/stores/settings-store.svelte";
- import { t } from "$lib/i18n";
-
- let downloads = $derived(getDownloads());
-
- type KajabiCourse = {
- id: string;
- name: string;
- thumbnail_url: string | null;
- site_id: string;
- };
-
- let token = $state("");
- let fileInput: HTMLInputElement = $state() as HTMLInputElement;
- function onFileSelected(e: Event) {
- const input = e.target as HTMLInputElement;
- const file = input.files?.[0];
- if (!file) return;
- const reader = new FileReader();
- reader.onload = () => { token = reader.result as string; };
- reader.readAsText(file);
- input.value = "";
- }
- let loading = $state(false);
- let error = $state("");
-
- let checking = $state(true);
- let loggedIn = $state(false);
- let sessionEmail = $state("");
-
- let courses: KajabiCourse[] = $state([]);
- let loadingCourses = $state(false);
- let coursesError = $state("");
-
- const ITEMS_PER_PAGE = 12;
- let currentPage = $state(1);
-
- let totalPages = $derived(Math.max(1, Math.ceil(courses.length / ITEMS_PER_PAGE)));
- let paginatedCourses = $derived(
- courses.slice((currentPage - 1) * ITEMS_PER_PAGE, currentPage * ITEMS_PER_PAGE)
- );
-
- let pageNumbers = $derived((): number[] => {
- const pages: number[] = [];
- if (totalPages <= 7) {
- for (let i = 1; i <= totalPages; i++) pages.push(i);
- } else {
- pages.push(1);
- if (currentPage > 3) pages.push(-1);
- const start = Math.max(2, currentPage - 1);
- const end = Math.min(totalPages - 1, currentPage + 1);
- for (let i = start; i <= end; i++) pages.push(i);
- if (currentPage < totalPages - 2) pages.push(-1);
- pages.push(totalPages);
- }
- return pages;
- });
-
- function goToPage(page: number) {
- if (page >= 1 && page <= totalPages) {
- currentPage = page;
- }
- }
-
- $effect(() => {
- checkSession();
- });
-
- async function checkSession() {
- try {
- const result = await pluginInvoke<string>("courses", "kajabi_check_session");
- sessionEmail = result;
- loggedIn = true;
- loadCourses();
- } catch {
- loggedIn = false;
- } finally {
- checking = false;
- }
- }
-
- async function handleTokenLogin() {
- if (!token.trim()) return;
- error = "";
- loading = true;
- try {
- const result = await pluginInvoke<string>("courses", "kajabi_login_token", { token: token.trim() });
- sessionEmail = result || "Token";
- loggedIn = true;
- loadCourses();
- } catch (e: any) {
- error = typeof e === "string" ? e : e.message ?? $t('hotmart.unknown_error');
- } finally {
- loading = false;
- }
- }
-
- async function handleLogout() {
- try {
- await pluginInvoke("courses", "kajabi_logout");
- } catch {
- }
- loggedIn = false;
- sessionEmail = "";
- courses = [];
- coursesError = "";
- currentPage = 1;
- }
-
- async function loadCourses() {
- loadingCourses = true;
- coursesError = "";
- try {
- courses = await pluginInvoke("courses", "kajabi_list_courses");
- currentPage = 1;
- } catch (e: any) {
- coursesError = typeof e === "string" ? e : e.message ?? $t('hotmart.courses_error');
- } finally {
- loadingCourses = false;
- }
- }
-
- function getCourseDownloadStatus(courseId: string): "idle" | "downloading" | "complete" | "error" {
- const item = downloads.get(Number(courseId) || 0);
- if (!item) return "idle";
- const s = item.status;
- if (s === "queued" || s === "paused" || s === "seeding") return "downloading";
- return s;
- }
-
- function getCourseDownloadPercent(courseId: string): number {
- return downloads.get(Number(courseId) || 0)?.percent ?? 0;
- }
-
- async function downloadCourse(course: KajabiCourse) {
- const status = getCourseDownloadStatus(course.id);
- if (status === "downloading") {
- showToast("info", $t("toast.download_already_active"));
- return;
- }
- if (status === "complete") return;
-
- const appSettings = getSettings();
- let outputDir: string | null = null;
-
- if (appSettings?.download.always_ask_path) {
- outputDir = await open({ directory: true, title: $t("hotmart.choose_folder") }) as string | null;
- if (!outputDir) return;
- } else {
- outputDir = appSettings?.download.default_output_dir ?? null;
- if (!outputDir) {
- outputDir = await open({ directory: true, title: $t("hotmart.choose_folder") }) as string | null;
- if (!outputDir) return;
- }
- }
-
- try {
- await pluginInvoke("courses", "start_kajabi_course_download", {
- courseJson: JSON.stringify(course),
- outputDir,
- });
- showToast("info", $t("toast.download_preparing"));
- } catch (e: any) {
- const msg = typeof e === "string" ? e : e.message ?? $t("common.error");
- showToast("error", msg);
- }
- }
-
- let refreshing = $state(false);
-
- async function refreshCourses() {
- refreshing = true;
- loadingCourses = true;
- coursesError = "";
- try {
- courses = await pluginInvoke("courses", "kajabi_refresh_courses");
- currentPage = 1;
- } catch (e: any) {
- coursesError = typeof e === "string" ? e : e.message ?? $t('hotmart.courses_error');
- } finally {
- loadingCourses = false;
- refreshing = false;
- }
- }
-</script>
-
-<a href="/courses" class="back-link">
- <svg viewBox="0 0 24 24" width="16" height="16" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
- <path d="M19 12H5" />
- <path d="M12 19l-7-7 7-7" />
- </svg>
- {$t("courses.back")}
-</a>
-
-{#if checking}
- <div class="page-center">
- <span class="spinner"></span>
- <span class="spinner-text">{$t('hotmart.checking_session')}</span>
- </div>
-{:else if loggedIn}
- <div class="page-logged">
- <div class="session-bar">
- <span class="session-info">
- {$t('hotmart.logged_as', { email: sessionEmail || "—" })}
- </span>
- <div class="session-actions">
- <button
- class="button"
- onclick={refreshCourses}
- disabled={refreshing}
- aria-label={$t('hotmart.refresh')}
- >
- <svg viewBox="0 0 24 24" width="14" height="14" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class:spinning={refreshing}>
- <path d="M21 2v6h-6" />
- <path d="M3 12a9 9 0 0115-6.7L21 8" />
- <path d="M3 22v-6h6" />
- <path d="M21 12a9 9 0 01-15 6.7L3 16" />
- </svg>
- </button>
- <button class="button" onclick={handleLogout}>{$t('hotmart.logout')}</button>
- </div>
- </div>
-
- {#if loadingCourses}
- <div class="spinner-section">
- <span class="spinner"></span>
- <span class="spinner-text">{$t('hotmart.loading_courses')}</span>
- </div>
- {:else if coursesError}
- <div class="error-section">
- <p class="error-msg">{coursesError}</p>
- <button class="button" onclick={loadCourses}>{$t('common.retry')}</button>
- </div>
- {:else if courses.length === 0}
- <p class="empty-text">{$t('hotmart.no_courses')}</p>
- {:else}
- <div class="courses-header">
- <h2>{$t('hotmart.courses_title')}</h2>
- <span class="subtext">{courses.length === 1 ? $t('hotmart.course_count_one', { count: courses.length }) : $t('hotmart.course_count', { count: courses.length })}</span>
- </div>
-
- <div class="courses-grid">
- {#each paginatedCourses as course (course.id)}
- <CourseCard
- name={course.name}
- price=""
- imageUrl={course.thumbnail_url ?? undefined}
- downloadStatus={getCourseDownloadStatus(course.id)}
- downloadPercent={getCourseDownloadPercent(course.id)}
- onDownload={() => downloadCourse(course)}
- />
- {/each}
- </div>
-
- {#if totalPages > 1}
- <div class="pagination">
- <span class="pagination-info">
- {$t('hotmart.page_of', { current: currentPage, total: totalPages })} &middot; {courses.length === 1 ? $t('hotmart.course_count_one', { count: courses.length }) : $t('hotmart.course_count', { count: courses.length })}
- </span>
- <div class="pagination-controls">
- <button
- class="button pagination-btn"
- disabled={currentPage <= 1}
- onclick={() => goToPage(currentPage - 1)}
- >
- &lt;
- </button>
-
- {#each pageNumbers() as page}
- {#if page === -1}
- <span class="pagination-ellipsis">&hellip;</span>
- {:else}
- <button
- class="button pagination-btn"
- class:active={page === currentPage}
- onclick={() => goToPage(page)}
- >
- {page}
- </button>
- {/if}
- {/each}
-
- <button
- class="button pagination-btn"
- disabled={currentPage >= totalPages}
- onclick={() => goToPage(currentPage + 1)}
- >
- &gt;
- </button>
- </div>
- </div>
- {/if}
- {/if}
- </div>
-{:else}
- <div class="page-center">
- <div class="login-card">
- <h2>Kajabi</h2>
-
- <div class="form">
- <label class="field">
- <span class="field-label">Cookies JSON</span>
- <textarea
- class="input token-textarea"
- placeholder="Paste cookies JSON from browser extension or a raw token"
- bind:value={token}
- disabled={loading}
- rows="4"
- ></textarea>
- </label>
- <input type="file" accept=".json,.txt" class="hidden-file-input" bind:this={fileInput} onchange={onFileSelected} />
- <button class="button" onclick={() => fileInput?.click()} disabled={loading}>Import .json file</button>
-
- {#if error}
- <p class="error-msg">{error}</p>
- {/if}
-
- <button class="button" onclick={handleTokenLogin} disabled={loading || !token.trim()}>
- {#if loading}
- {$t('hotmart.authenticating')}
- {:else}
- {$t('hotmart.login')}
- {/if}
- </button>
- </div>
- </div>
- </div>
-{/if}
-
-<style>
- .back-link {
- display: inline-flex;
- align-items: center;
- gap: 6px;
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- margin-bottom: var(--padding);
- }
-
- @media (hover: hover) {
- .back-link:hover {
- color: var(--secondary);
- }
- }
-
- .page-center {
- display: flex;
- flex-direction: column;
- align-items: center;
- justify-content: center;
- min-height: calc(100vh - var(--padding) * 4 - 40px);
- gap: var(--padding);
- }
-
- .page-logged {
- display: flex;
- flex-direction: column;
- align-items: center;
- gap: calc(var(--padding) * 1.5);
- padding: calc(var(--padding) * 1.5);
- width: 100%;
- }
-
- .page-logged > :global(*) {
- width: 100%;
- max-width: 1200px;
- }
-
- .session-bar {
- display: flex;
- align-items: center;
- justify-content: space-between;
- }
-
- .session-info {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .session-actions {
- display: flex;
- gap: calc(var(--padding) / 2);
- }
-
- .session-bar :global(.button) {
- padding: calc(var(--padding) / 2) var(--padding);
- font-size: 12.5px;
- }
-
- .spinning {
- animation: spin 0.6s linear infinite;
- }
-
- .courses-header {
- display: flex;
- align-items: baseline;
- gap: var(--padding);
- }
-
- .courses-header h2 {
- margin-block: 0;
- }
-
- .subtext {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .courses-grid {
- display: grid;
- grid-template-columns: repeat(4, 1fr);
- gap: var(--padding);
- }
-
- @media (max-width: 1000px) {
- .courses-grid {
- grid-template-columns: repeat(3, 1fr);
- }
- }
-
- @media (max-width: 750px) {
- .courses-grid {
- grid-template-columns: repeat(2, 1fr);
- }
- }
-
- @media (max-width: 535px) {
- .courses-grid {
- grid-template-columns: 1fr;
- }
- }
-
- .pagination {
- display: flex;
- flex-direction: column;
- align-items: center;
- gap: var(--padding);
- padding-top: var(--padding);
- }
-
- .pagination-info {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .pagination-controls {
- display: flex;
- align-items: center;
- gap: calc(var(--padding) / 3);
- }
-
- .pagination-btn {
- min-width: 36px;
- height: 36px;
- padding: 0;
- display: flex;
- align-items: center;
- justify-content: center;
- font-size: 14.5px;
- }
-
- .pagination-ellipsis {
- min-width: 36px;
- text-align: center;
- color: var(--gray);
- font-size: 14.5px;
- }
-
- .login-card {
- width: 100%;
- max-width: 400px;
- background: var(--button-elevated);
- border-radius: var(--border-radius);
- padding: calc(var(--padding) * 2);
- display: flex;
- flex-direction: column;
- gap: calc(var(--padding) * 1.5);
- }
-
- .login-card h2 {
- margin-block: 0;
- }
-
- .hidden-file-input {
- display: none;
- }
-
- .token-textarea {
- resize: vertical;
- min-height: 80px;
- font-size: 11.5px;
- font-family: var(--font-mono);
- line-height: 1.5;
- }
-
- .form {
- display: flex;
- flex-direction: column;
- gap: var(--padding);
- }
-
- .field {
- display: flex;
- flex-direction: column;
- gap: calc(var(--padding) / 2);
- }
-
- .field-label {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .input {
- width: 100%;
- padding: var(--padding);
- font-size: 14.5px;
- background: var(--button);
- border-radius: var(--border-radius);
- color: var(--secondary);
- border: 1px solid var(--input-border);
- }
-
- .input::placeholder {
- color: var(--gray);
- }
-
- .input:focus-visible {
- border-color: var(--secondary);
- outline: none;
- }
-
- .input:disabled {
- opacity: 0.5;
- cursor: default;
- }
-
- .error-msg {
- color: var(--red);
- font-size: 12.5px;
- font-weight: 500;
- }
-
- .spinner-section {
- display: flex;
- flex-direction: column;
- align-items: center;
- gap: var(--padding);
- padding: calc(var(--padding) * 4) 0;
- }
-
- .spinner {
- width: 24px;
- height: 24px;
- border: 2px solid var(--input-border);
- border-top-color: var(--blue);
- border-radius: 50%;
- animation: spin 0.6s linear infinite;
- }
-
- @keyframes spin {
- to {
- transform: rotate(360deg);
- }
- }
-
- .spinner-text {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .error-section {
- display: flex;
- flex-direction: column;
- align-items: center;
- gap: var(--padding);
- padding: calc(var(--padding) * 2) 0;
- }
-
- .empty-text {
- color: var(--gray);
- font-size: 14.5px;
- text-align: center;
- padding: calc(var(--padding) * 4) 0;
- }
-</style>
diff --git a/src/routes/courses/kirvano/+page.svelte b/src/routes/courses/kirvano/+page.svelte
deleted file mode 100644
index 566524c3..00000000
--- a/src/routes/courses/kirvano/+page.svelte
+++ /dev/null
@@ -1,704 +0,0 @@
-<script lang="ts">
- import { pluginInvoke } from "$lib/plugin-invoke";
- import { open } from "@tauri-apps/plugin-dialog";
- import CourseCard from "$components/hotmart/CourseCard.svelte";
- import { showToast } from "$lib/stores/toast-store.svelte";
- import { getDownloads } from "$lib/stores/download-store.svelte";
- import { getSettings } from "$lib/stores/settings-store.svelte";
- import { t } from "$lib/i18n";
-
- let downloads = $derived(getDownloads());
-
- type KirvanoCourse = {
- id: string;
- name: string;
- seller: string;
- image_url: string | null;
- course_uuid: string;
- };
-
- let email = $state("");
- let password = $state("");
- let token = $state("");
- let loading = $state(false);
- let error = $state("");
-
- let checking = $state(true);
- let loggedIn = $state(false);
- let sessionEmail = $state("");
-
- let loginMode = $state<"credentials" | "token">("credentials");
-
- let fileInput: HTMLInputElement = $state() as HTMLInputElement;
-
- function onFileSelected(e: Event) {
- const input = e.target as HTMLInputElement;
- const file = input.files?.[0];
- if (!file) return;
- const reader = new FileReader();
- reader.onload = () => { token = reader.result as string; };
- reader.readAsText(file);
- input.value = "";
- }
-
- let courses: KirvanoCourse[] = $state([]);
- let loadingCourses = $state(false);
- let coursesError = $state("");
-
- const ITEMS_PER_PAGE = 12;
- let currentPage = $state(1);
-
- let totalPages = $derived(Math.max(1, Math.ceil(courses.length / ITEMS_PER_PAGE)));
- let paginatedCourses = $derived(
- courses.slice((currentPage - 1) * ITEMS_PER_PAGE, currentPage * ITEMS_PER_PAGE)
- );
-
- let pageNumbers = $derived((): number[] => {
- const pages: number[] = [];
- if (totalPages <= 7) {
- for (let i = 1; i <= totalPages; i++) pages.push(i);
- } else {
- pages.push(1);
- if (currentPage > 3) pages.push(-1);
- const start = Math.max(2, currentPage - 1);
- const end = Math.min(totalPages - 1, currentPage + 1);
- for (let i = start; i <= end; i++) pages.push(i);
- if (currentPage < totalPages - 2) pages.push(-1);
- pages.push(totalPages);
- }
- return pages;
- });
-
- function goToPage(page: number) {
- if (page >= 1 && page <= totalPages) {
- currentPage = page;
- }
- }
-
- $effect(() => {
- checkSession();
- });
-
- async function checkSession() {
- try {
- const result = await pluginInvoke<string>("courses", "kirvano_check_session");
- sessionEmail = result;
- loggedIn = true;
- loadCourses();
- } catch {
- loggedIn = false;
- } finally {
- checking = false;
- }
- }
-
- async function handleLogin() {
- error = "";
- loading = true;
- try {
- const result = await pluginInvoke<string>("courses", "kirvano_login", { email, password });
- sessionEmail = result || email;
- loggedIn = true;
- loadCourses();
- } catch (e: any) {
- error = typeof e === "string" ? e : e.message ?? $t('hotmart.unknown_error');
- } finally {
- loading = false;
- }
- }
-
- async function handleTokenLogin() {
- if (!token.trim()) return;
- error = "";
- loading = true;
- try {
- const result = await pluginInvoke<string>("courses", "kirvano_login_token", { token: token.trim() });
- sessionEmail = result || "Token";
- loggedIn = true;
- loadCourses();
- } catch (e: any) {
- error = typeof e === "string" ? e : e.message ?? $t('hotmart.unknown_error');
- } finally {
- loading = false;
- }
- }
-
- async function handleLogout() {
- try {
- await pluginInvoke("courses", "kirvano_logout");
- } catch {
- }
- loggedIn = false;
- sessionEmail = "";
- courses = [];
- coursesError = "";
- currentPage = 1;
- }
-
- async function loadCourses() {
- loadingCourses = true;
- coursesError = "";
- try {
- courses = await pluginInvoke("courses", "kirvano_list_courses");
- currentPage = 1;
- } catch (e: any) {
- coursesError = typeof e === "string" ? e : e.message ?? $t('hotmart.courses_error');
- } finally {
- loadingCourses = false;
- }
- }
-
- function getCourseDownloadStatus(courseId: number): "idle" | "downloading" | "complete" | "error" {
- const item = downloads.get(courseId);
- if (!item) return "idle";
- const s = item.status;
- if (s === "queued" || s === "paused" || s === "seeding") return "downloading";
- return s;
- }
-
- function getCourseDownloadPercent(courseId: number): number {
- return downloads.get(courseId)?.percent ?? 0;
- }
-
- async function downloadCourse(course: KirvanoCourse) {
- const status = getCourseDownloadStatus(Number(course.id) || 0);
- if (status === "downloading") {
- showToast("info", $t("toast.download_already_active"));
- return;
- }
- if (status === "complete") return;
-
- const appSettings = getSettings();
- let outputDir: string | null = null;
-
- if (appSettings?.download.always_ask_path) {
- outputDir = await open({ directory: true, title: $t("hotmart.choose_folder") }) as string | null;
- if (!outputDir) return;
- } else {
- outputDir = appSettings?.download.default_output_dir ?? null;
- if (!outputDir) {
- outputDir = await open({ directory: true, title: $t("hotmart.choose_folder") }) as string | null;
- if (!outputDir) return;
- }
- }
-
- try {
- await pluginInvoke("courses", "start_kirvano_course_download", {
- courseJson: JSON.stringify(course),
- outputDir,
- });
- showToast("info", $t("toast.download_preparing"));
- } catch (e: any) {
- const msg = typeof e === "string" ? e : e.message ?? $t("common.error");
- showToast("error", msg);
- }
- }
-
- let refreshing = $state(false);
-
- async function refreshCourses() {
- refreshing = true;
- loadingCourses = true;
- coursesError = "";
- try {
- courses = await pluginInvoke("courses", "kirvano_refresh_courses");
- currentPage = 1;
- } catch (e: any) {
- coursesError = typeof e === "string" ? e : e.message ?? $t('hotmart.courses_error');
- } finally {
- loadingCourses = false;
- refreshing = false;
- }
- }
-</script>
-
-<a href="/courses" class="back-link">
- <svg viewBox="0 0 24 24" width="16" height="16" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
- <path d="M19 12H5" />
- <path d="M12 19l-7-7 7-7" />
- </svg>
- {$t("courses.back")}
-</a>
-
-{#if checking}
- <div class="page-center">
- <span class="spinner"></span>
- <span class="spinner-text">{$t('hotmart.checking_session')}</span>
- </div>
-{:else if loggedIn}
- <div class="page-logged">
- <div class="session-bar">
- <span class="session-info">
- {$t('hotmart.logged_as', { email: sessionEmail || "—" })}
- </span>
- <div class="session-actions">
- <button
- class="button"
- onclick={refreshCourses}
- disabled={refreshing}
- aria-label={$t('hotmart.refresh')}
- >
- <svg viewBox="0 0 24 24" width="14" height="14" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class:spinning={refreshing}>
- <path d="M21 2v6h-6" />
- <path d="M3 12a9 9 0 0115-6.7L21 8" />
- <path d="M3 22v-6h6" />
- <path d="M21 12a9 9 0 01-15 6.7L3 16" />
- </svg>
- </button>
- <button class="button" onclick={handleLogout}>{$t('hotmart.logout')}</button>
- </div>
- </div>
-
- {#if loadingCourses}
- <div class="spinner-section">
- <span class="spinner"></span>
- <span class="spinner-text">{$t('hotmart.loading_courses')}</span>
- </div>
- {:else if coursesError}
- <div class="error-section">
- <p class="error-msg">{coursesError}</p>
- <button class="button" onclick={loadCourses}>{$t('common.retry')}</button>
- </div>
- {:else if courses.length === 0}
- <p class="empty-text">{$t('hotmart.no_courses')}</p>
- {:else}
- <div class="courses-header">
- <h2>{$t('hotmart.courses_title')}</h2>
- <span class="subtext">{courses.length === 1 ? $t('hotmart.course_count_one', { count: courses.length }) : $t('hotmart.course_count', { count: courses.length })}</span>
- </div>
-
- <div class="courses-grid">
- {#each paginatedCourses as course (course.id)}
- <CourseCard
- name={course.name}
- price={course.seller}
- imageUrl={course.image_url ?? undefined}
- downloadStatus={getCourseDownloadStatus(Number(course.id) || 0)}
- downloadPercent={getCourseDownloadPercent(Number(course.id) || 0)}
- onDownload={() => downloadCourse(course)}
- />
- {/each}
- </div>
-
- {#if totalPages > 1}
- <div class="pagination">
- <span class="pagination-info">
- {$t('hotmart.page_of', { current: currentPage, total: totalPages })} &middot; {courses.length === 1 ? $t('hotmart.course_count_one', { count: courses.length }) : $t('hotmart.course_count', { count: courses.length })}
- </span>
- <div class="pagination-controls">
- <button
- class="button pagination-btn"
- disabled={currentPage <= 1}
- onclick={() => goToPage(currentPage - 1)}
- >
- &lt;
- </button>
-
- {#each pageNumbers() as page}
- {#if page === -1}
- <span class="pagination-ellipsis">&hellip;</span>
- {:else}
- <button
- class="button pagination-btn"
- class:active={page === currentPage}
- onclick={() => goToPage(page)}
- >
- {page}
- </button>
- {/if}
- {/each}
-
- <button
- class="button pagination-btn"
- disabled={currentPage >= totalPages}
- onclick={() => goToPage(currentPage + 1)}
- >
- &gt;
- </button>
- </div>
- </div>
- {/if}
- {/if}
- </div>
-{:else}
- <div class="page-center">
- <div class="login-card">
- <h2>Kirvano</h2>
-
- <div class="login-tabs">
- <button
- class="button login-tab"
- class:active={loginMode === "credentials"}
- onclick={() => { loginMode = "credentials"; error = ""; }}
- >
- Email & Password
- </button>
- <button
- class="button login-tab"
- class:active={loginMode === "token"}
- onclick={() => { loginMode = "token"; error = ""; }}
- >
- Token
- </button>
- </div>
-
- {#if loginMode === "credentials"}
- <form class="form" onsubmit={(e) => { e.preventDefault(); handleLogin(); }}>
- <label class="field">
- <span class="field-label">{$t('hotmart.email_label')}</span>
- <input
- type="email"
- placeholder={$t('hotmart.email_placeholder')}
- bind:value={email}
- class="input"
- disabled={loading}
- required
- />
- </label>
- <label class="field">
- <span class="field-label">{$t('hotmart.password_label')}</span>
- <input
- type="password"
- placeholder={$t('hotmart.password_placeholder')}
- bind:value={password}
- class="input"
- disabled={loading}
- required
- />
- </label>
-
- {#if error}
- <p class="error-msg">{error}</p>
- {/if}
-
- <button type="submit" class="button" disabled={loading}>
- {#if loading}
- {$t('hotmart.authenticating')}
- {:else}
- {$t('hotmart.login')}
- {/if}
- </button>
- </form>
- {:else}
- <div class="form">
- <label class="field">
- <span class="field-label">Cookies JSON</span>
- <textarea
- class="input token-textarea"
- placeholder="Paste cookies JSON from browser extension or a raw token"
- bind:value={token}
- disabled={loading}
- rows="5"
- ></textarea>
- </label>
-
- <input
- type="file"
- accept=".json,.txt"
- class="hidden-file-input"
- bind:this={fileInput}
- onchange={onFileSelected}
- />
- <button class="button" onclick={() => fileInput?.click()} disabled={loading}>
- Import .json file
- </button>
-
- {#if error}
- <p class="error-msg">{error}</p>
- {/if}
-
- <button class="button" onclick={handleTokenLogin} disabled={loading || !token.trim()}>
- {#if loading}
- {$t('hotmart.authenticating')}
- {:else}
- {$t('hotmart.login')}
- {/if}
- </button>
- </div>
- {/if}
- </div>
- </div>
-{/if}
-
-<style>
- .back-link {
- display: inline-flex;
- align-items: center;
- gap: 6px;
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- margin-bottom: var(--padding);
- }
-
- @media (hover: hover) {
- .back-link:hover {
- color: var(--secondary);
- }
- }
-
- .page-center {
- display: flex;
- flex-direction: column;
- align-items: center;
- justify-content: center;
- min-height: calc(100vh - var(--padding) * 4 - 40px);
- gap: var(--padding);
- }
-
- .page-logged {
- display: flex;
- flex-direction: column;
- align-items: center;
- gap: calc(var(--padding) * 1.5);
- padding: calc(var(--padding) * 1.5);
- width: 100%;
- }
-
- .page-logged > :global(*) {
- width: 100%;
- max-width: 1200px;
- }
-
- .session-bar {
- display: flex;
- align-items: center;
- justify-content: space-between;
- }
-
- .session-info {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .session-actions {
- display: flex;
- gap: calc(var(--padding) / 2);
- }
-
- .session-bar :global(.button) {
- padding: calc(var(--padding) / 2) var(--padding);
- font-size: 12.5px;
- }
-
- .spinning {
- animation: spin 0.6s linear infinite;
- }
-
- .courses-header {
- display: flex;
- align-items: baseline;
- gap: var(--padding);
- }
-
- .courses-header h2 {
- margin-block: 0;
- }
-
- .subtext {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .courses-grid {
- display: grid;
- grid-template-columns: repeat(4, 1fr);
- gap: var(--padding);
- }
-
- @media (max-width: 1000px) {
- .courses-grid {
- grid-template-columns: repeat(3, 1fr);
- }
- }
-
- @media (max-width: 750px) {
- .courses-grid {
- grid-template-columns: repeat(2, 1fr);
- }
- }
-
- @media (max-width: 535px) {
- .courses-grid {
- grid-template-columns: 1fr;
- }
- }
-
- .pagination {
- display: flex;
- flex-direction: column;
- align-items: center;
- gap: var(--padding);
- padding-top: var(--padding);
- }
-
- .pagination-info {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .pagination-controls {
- display: flex;
- align-items: center;
- gap: calc(var(--padding) / 3);
- }
-
- .pagination-btn {
- min-width: 36px;
- height: 36px;
- padding: 0;
- display: flex;
- align-items: center;
- justify-content: center;
- font-size: 14.5px;
- }
-
- .pagination-ellipsis {
- min-width: 36px;
- text-align: center;
- color: var(--gray);
- font-size: 14.5px;
- }
-
- .login-card {
- width: 100%;
- max-width: 400px;
- background: var(--button-elevated);
- border-radius: var(--border-radius);
- padding: calc(var(--padding) * 2);
- display: flex;
- flex-direction: column;
- gap: calc(var(--padding) * 1.5);
- }
-
- .login-card h2 {
- margin-block: 0;
- }
-
- .login-tabs {
- display: flex;
- gap: 0;
- }
-
- .login-tab {
- flex: 1;
- border-radius: 0;
- font-size: 12.5px;
- padding: calc(var(--padding) * 0.75) var(--padding);
- }
-
- .login-tab:first-child {
- border-radius: var(--border-radius) 0 0 var(--border-radius);
- }
-
- .login-tab:last-child {
- border-radius: 0 var(--border-radius) var(--border-radius) 0;
- }
-
- .hidden-file-input {
- display: none;
- }
-
- .token-textarea {
- resize: vertical;
- min-height: 80px;
- font-size: 11.5px;
- font-family: var(--font-mono);
- line-height: 1.5;
- }
-
- .form {
- display: flex;
- flex-direction: column;
- gap: var(--padding);
- }
-
- .field {
- display: flex;
- flex-direction: column;
- gap: calc(var(--padding) / 2);
- }
-
- .field-label {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .input {
- width: 100%;
- padding: var(--padding);
- font-size: 14.5px;
- background: var(--button);
- border-radius: var(--border-radius);
- color: var(--secondary);
- border: 1px solid var(--input-border);
- }
-
- .input::placeholder {
- color: var(--gray);
- }
-
- .input:focus-visible {
- border-color: var(--secondary);
- outline: none;
- }
-
- .input:disabled {
- opacity: 0.5;
- cursor: default;
- }
-
- .error-msg {
- color: var(--red);
- font-size: 12.5px;
- font-weight: 500;
- }
-
- .spinner-section {
- display: flex;
- flex-direction: column;
- align-items: center;
- gap: var(--padding);
- padding: calc(var(--padding) * 4) 0;
- }
-
- .spinner {
- width: 24px;
- height: 24px;
- border: 2px solid var(--input-border);
- border-top-color: var(--blue);
- border-radius: 50%;
- animation: spin 0.6s linear infinite;
- }
-
- @keyframes spin {
- to {
- transform: rotate(360deg);
- }
- }
-
- .spinner-text {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .error-section {
- display: flex;
- flex-direction: column;
- align-items: center;
- gap: var(--padding);
- padding: calc(var(--padding) * 2) 0;
- }
-
- .empty-text {
- color: var(--gray);
- font-size: 14.5px;
- text-align: center;
- padding: calc(var(--padding) * 4) 0;
- }
-</style>
diff --git a/src/routes/courses/kiwify/+page.svelte b/src/routes/courses/kiwify/+page.svelte
deleted file mode 100644
index 54a305c8..00000000
--- a/src/routes/courses/kiwify/+page.svelte
+++ /dev/null
@@ -1,693 +0,0 @@
-<script lang="ts">
- import { pluginInvoke } from "$lib/plugin-invoke";
- import { open } from "@tauri-apps/plugin-dialog";
- import CourseCard from "$components/hotmart/CourseCard.svelte";
- import { showToast } from "$lib/stores/toast-store.svelte";
- import { getDownloads } from "$lib/stores/download-store.svelte";
- import { getSettings } from "$lib/stores/settings-store.svelte";
- import { t } from "$lib/i18n";
-
- let downloads = $derived(getDownloads());
-
- type KiwifyCourse = {
- id: number;
- name: string;
- seller: string;
- image_url: string | null;
- is_school: boolean;
- };
-
- let email = $state("");
- let password = $state("");
- let token = $state("");
- let fileInput: HTMLInputElement = $state() as HTMLInputElement;
- function onFileSelected(e: Event) {
- const input = e.target as HTMLInputElement;
- const file = input.files?.[0];
- if (!file) return;
- const reader = new FileReader();
- reader.onload = () => { token = reader.result as string; };
- reader.readAsText(file);
- input.value = "";
- }
- let loading = $state(false);
- let error = $state("");
-
- let checking = $state(true);
- let loggedIn = $state(false);
- let sessionEmail = $state("");
-
- let loginMode = $state<"credentials" | "token">("credentials");
-
- let courses: KiwifyCourse[] = $state([]);
- let loadingCourses = $state(false);
- let coursesError = $state("");
-
- const ITEMS_PER_PAGE = 12;
- let currentPage = $state(1);
-
- let totalPages = $derived(Math.max(1, Math.ceil(courses.length / ITEMS_PER_PAGE)));
- let paginatedCourses = $derived(
- courses.slice((currentPage - 1) * ITEMS_PER_PAGE, currentPage * ITEMS_PER_PAGE)
- );
-
- let pageNumbers = $derived((): number[] => {
- const pages: number[] = [];
- if (totalPages <= 7) {
- for (let i = 1; i <= totalPages; i++) pages.push(i);
- } else {
- pages.push(1);
- if (currentPage > 3) pages.push(-1);
- const start = Math.max(2, currentPage - 1);
- const end = Math.min(totalPages - 1, currentPage + 1);
- for (let i = start; i <= end; i++) pages.push(i);
- if (currentPage < totalPages - 2) pages.push(-1);
- pages.push(totalPages);
- }
- return pages;
- });
-
- function goToPage(page: number) {
- if (page >= 1 && page <= totalPages) {
- currentPage = page;
- }
- }
-
- $effect(() => {
- checkSession();
- });
-
- async function checkSession() {
- try {
- const result = await pluginInvoke<string>("courses", "kiwify_check_session");
- sessionEmail = result;
- loggedIn = true;
- loadCourses();
- } catch {
- loggedIn = false;
- } finally {
- checking = false;
- }
- }
-
- async function handleLogin() {
- error = "";
- loading = true;
- try {
- const result = await pluginInvoke<string>("courses", "kiwify_login", { email, password });
- sessionEmail = result || email;
- loggedIn = true;
- loadCourses();
- } catch (e: any) {
- error = typeof e === "string" ? e : e.message ?? $t('hotmart.unknown_error');
- } finally {
- loading = false;
- }
- }
-
- async function handleTokenLogin() {
- if (!token.trim()) return;
- error = "";
- loading = true;
- try {
- const result = await pluginInvoke<string>("courses", "kiwify_login_token", { token: token.trim() });
- sessionEmail = result || "Token";
- loggedIn = true;
- loadCourses();
- } catch (e: any) {
- error = typeof e === "string" ? e : e.message ?? $t('hotmart.unknown_error');
- } finally {
- loading = false;
- }
- }
-
- async function handleLogout() {
- try {
- await pluginInvoke("courses", "kiwify_logout");
- } catch {
- }
- loggedIn = false;
- sessionEmail = "";
- courses = [];
- coursesError = "";
- currentPage = 1;
- }
-
- async function loadCourses() {
- loadingCourses = true;
- coursesError = "";
- try {
- courses = await pluginInvoke("courses", "kiwify_list_courses");
- currentPage = 1;
- } catch (e: any) {
- coursesError = typeof e === "string" ? e : e.message ?? $t('hotmart.courses_error');
- } finally {
- loadingCourses = false;
- }
- }
-
- function getCourseDownloadStatus(courseId: number): "idle" | "downloading" | "complete" | "error" {
- const item = downloads.get(courseId);
- if (!item) return "idle";
- const s = item.status;
- if (s === "queued" || s === "paused" || s === "seeding") return "downloading";
- return s;
- }
-
- function getCourseDownloadPercent(courseId: number): number {
- return downloads.get(courseId)?.percent ?? 0;
- }
-
- async function downloadCourse(course: KiwifyCourse) {
- const status = getCourseDownloadStatus(course.id);
- if (status === "downloading") {
- showToast("info", $t("toast.download_already_active"));
- return;
- }
- if (status === "complete") return;
-
- const appSettings = getSettings();
- let outputDir: string | null = null;
-
- if (appSettings?.download.always_ask_path) {
- outputDir = await open({ directory: true, title: $t("hotmart.choose_folder") }) as string | null;
- if (!outputDir) return;
- } else {
- outputDir = appSettings?.download.default_output_dir ?? null;
- if (!outputDir) {
- outputDir = await open({ directory: true, title: $t("hotmart.choose_folder") }) as string | null;
- if (!outputDir) return;
- }
- }
-
- try {
- await pluginInvoke("courses", "start_kiwify_course_download", {
- courseJson: JSON.stringify(course),
- outputDir,
- });
- showToast("info", $t("toast.download_preparing"));
- } catch (e: any) {
- const msg = typeof e === "string" ? e : e.message ?? $t("common.error");
- showToast("error", msg);
- }
- }
-
- let refreshing = $state(false);
-
- async function refreshCourses() {
- refreshing = true;
- loadingCourses = true;
- coursesError = "";
- try {
- courses = await pluginInvoke("courses", "kiwify_refresh_courses");
- currentPage = 1;
- } catch (e: any) {
- coursesError = typeof e === "string" ? e : e.message ?? $t('hotmart.courses_error');
- } finally {
- loadingCourses = false;
- refreshing = false;
- }
- }
-</script>
-
-<a href="/courses" class="back-link">
- <svg viewBox="0 0 24 24" width="16" height="16" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
- <path d="M19 12H5" />
- <path d="M12 19l-7-7 7-7" />
- </svg>
- {$t("courses.back")}
-</a>
-
-{#if checking}
- <div class="page-center">
- <span class="spinner"></span>
- <span class="spinner-text">{$t('hotmart.checking_session')}</span>
- </div>
-{:else if loggedIn}
- <div class="page-logged">
- <div class="session-bar">
- <span class="session-info">
- {$t('hotmart.logged_as', { email: sessionEmail || "—" })}
- </span>
- <div class="session-actions">
- <button
- class="button"
- onclick={refreshCourses}
- disabled={refreshing}
- aria-label={$t('hotmart.refresh')}
- >
- <svg viewBox="0 0 24 24" width="14" height="14" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class:spinning={refreshing}>
- <path d="M21 2v6h-6" />
- <path d="M3 12a9 9 0 0115-6.7L21 8" />
- <path d="M3 22v-6h6" />
- <path d="M21 12a9 9 0 01-15 6.7L3 16" />
- </svg>
- </button>
- <button class="button" onclick={handleLogout}>{$t('hotmart.logout')}</button>
- </div>
- </div>
-
- {#if loadingCourses}
- <div class="spinner-section">
- <span class="spinner"></span>
- <span class="spinner-text">{$t('hotmart.loading_courses')}</span>
- </div>
- {:else if coursesError}
- <div class="error-section">
- <p class="error-msg">{coursesError}</p>
- <button class="button" onclick={loadCourses}>{$t('common.retry')}</button>
- </div>
- {:else if courses.length === 0}
- <p class="empty-text">{$t('hotmart.no_courses')}</p>
- {:else}
- <div class="courses-header">
- <h2>{$t('hotmart.courses_title')}</h2>
- <span class="subtext">{courses.length === 1 ? $t('hotmart.course_count_one', { count: courses.length }) : $t('hotmart.course_count', { count: courses.length })}</span>
- </div>
-
- <div class="courses-grid">
- {#each paginatedCourses as course (course.id)}
- <CourseCard
- name={course.name}
- price={course.seller}
- imageUrl={course.image_url ?? undefined}
- downloadStatus={getCourseDownloadStatus(course.id)}
- downloadPercent={getCourseDownloadPercent(course.id)}
- onDownload={() => downloadCourse(course)}
- />
- {/each}
- </div>
-
- {#if totalPages > 1}
- <div class="pagination">
- <span class="pagination-info">
- {$t('hotmart.page_of', { current: currentPage, total: totalPages })} &middot; {courses.length === 1 ? $t('hotmart.course_count_one', { count: courses.length }) : $t('hotmart.course_count', { count: courses.length })}
- </span>
- <div class="pagination-controls">
- <button
- class="button pagination-btn"
- disabled={currentPage <= 1}
- onclick={() => goToPage(currentPage - 1)}
- >
- &lt;
- </button>
-
- {#each pageNumbers() as page}
- {#if page === -1}
- <span class="pagination-ellipsis">&hellip;</span>
- {:else}
- <button
- class="button pagination-btn"
- class:active={page === currentPage}
- onclick={() => goToPage(page)}
- >
- {page}
- </button>
- {/if}
- {/each}
-
- <button
- class="button pagination-btn"
- disabled={currentPage >= totalPages}
- onclick={() => goToPage(currentPage + 1)}
- >
- &gt;
- </button>
- </div>
- </div>
- {/if}
- {/if}
- </div>
-{:else}
- <div class="page-center">
- <div class="login-card">
- <h2>Kiwify</h2>
-
- <div class="login-tabs">
- <button
- class="button login-tab"
- class:active={loginMode === "credentials"}
- onclick={() => { loginMode = "credentials"; error = ""; }}
- >
- Email & Password
- </button>
- <button
- class="button login-tab"
- class:active={loginMode === "token"}
- onclick={() => { loginMode = "token"; error = ""; }}
- >
- Token
- </button>
- </div>
-
- {#if loginMode === "credentials"}
- <form class="form" onsubmit={(e) => { e.preventDefault(); handleLogin(); }}>
- <label class="field">
- <span class="field-label">{$t('hotmart.email_label')}</span>
- <input
- type="email"
- placeholder={$t('hotmart.email_placeholder')}
- bind:value={email}
- class="input"
- disabled={loading}
- required
- />
- </label>
- <label class="field">
- <span class="field-label">{$t('hotmart.password_label')}</span>
- <input
- type="password"
- placeholder={$t('hotmart.password_placeholder')}
- bind:value={password}
- class="input"
- disabled={loading}
- required
- />
- </label>
-
- {#if error}
- <p class="error-msg">{error}</p>
- {/if}
-
- <button type="submit" class="button" disabled={loading}>
- {#if loading}
- {$t('hotmart.authenticating')}
- {:else}
- {$t('hotmart.login')}
- {/if}
- </button>
- </form>
- {:else}
- <div class="form">
- <label class="field">
- <span class="field-label">Cookies JSON</span>
- <textarea
- class="input token-textarea"
- placeholder="Paste cookies JSON from browser extension or a raw token"
- bind:value={token}
- disabled={loading}
- rows="4"
- ></textarea>
- </label>
- <input type="file" accept=".json,.txt" class="hidden-file-input" bind:this={fileInput} onchange={onFileSelected} />
- <button class="button" onclick={() => fileInput?.click()} disabled={loading}>Import .json file</button>
-
- {#if error}
- <p class="error-msg">{error}</p>
- {/if}
-
- <button class="button" onclick={handleTokenLogin} disabled={loading || !token.trim()}>
- {#if loading}
- {$t('hotmart.authenticating')}
- {:else}
- {$t('hotmart.login')}
- {/if}
- </button>
- </div>
- {/if}
- </div>
- </div>
-{/if}
-
-<style>
- .back-link {
- display: inline-flex;
- align-items: center;
- gap: 6px;
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- margin-bottom: var(--padding);
- }
-
- @media (hover: hover) {
- .back-link:hover {
- color: var(--secondary);
- }
- }
-
- .page-center {
- display: flex;
- flex-direction: column;
- align-items: center;
- justify-content: center;
- min-height: calc(100vh - var(--padding) * 4 - 40px);
- gap: var(--padding);
- }
-
- .page-logged {
- display: flex;
- flex-direction: column;
- align-items: center;
- gap: calc(var(--padding) * 1.5);
- padding: calc(var(--padding) * 1.5);
- width: 100%;
- }
-
- .page-logged > :global(*) {
- width: 100%;
- max-width: 1200px;
- }
-
- .session-bar {
- display: flex;
- align-items: center;
- justify-content: space-between;
- }
-
- .session-info {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .session-actions {
- display: flex;
- gap: calc(var(--padding) / 2);
- }
-
- .session-bar :global(.button) {
- padding: calc(var(--padding) / 2) var(--padding);
- font-size: 12.5px;
- }
-
- .spinning {
- animation: spin 0.6s linear infinite;
- }
-
- .courses-header {
- display: flex;
- align-items: baseline;
- gap: var(--padding);
- }
-
- .courses-header h2 {
- margin-block: 0;
- }
-
- .subtext {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .courses-grid {
- display: grid;
- grid-template-columns: repeat(4, 1fr);
- gap: var(--padding);
- }
-
- @media (max-width: 1000px) {
- .courses-grid {
- grid-template-columns: repeat(3, 1fr);
- }
- }
-
- @media (max-width: 750px) {
- .courses-grid {
- grid-template-columns: repeat(2, 1fr);
- }
- }
-
- @media (max-width: 535px) {
- .courses-grid {
- grid-template-columns: 1fr;
- }
- }
-
- .pagination {
- display: flex;
- flex-direction: column;
- align-items: center;
- gap: var(--padding);
- padding-top: var(--padding);
- }
-
- .pagination-info {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .pagination-controls {
- display: flex;
- align-items: center;
- gap: calc(var(--padding) / 3);
- }
-
- .pagination-btn {
- min-width: 36px;
- height: 36px;
- padding: 0;
- display: flex;
- align-items: center;
- justify-content: center;
- font-size: 14.5px;
- }
-
- .pagination-ellipsis {
- min-width: 36px;
- text-align: center;
- color: var(--gray);
- font-size: 14.5px;
- }
-
- .login-card {
- width: 100%;
- max-width: 400px;
- background: var(--button-elevated);
- border-radius: var(--border-radius);
- padding: calc(var(--padding) * 2);
- display: flex;
- flex-direction: column;
- gap: calc(var(--padding) * 1.5);
- }
-
- .login-card h2 {
- margin-block: 0;
- }
-
- .login-tabs {
- display: flex;
- gap: 0;
- }
-
- .login-tab {
- flex: 1;
- border-radius: 0;
- font-size: 12.5px;
- padding: calc(var(--padding) * 0.75) var(--padding);
- }
-
- .login-tab:first-child {
- border-radius: var(--border-radius) 0 0 var(--border-radius);
- }
-
- .login-tab:last-child {
- border-radius: 0 var(--border-radius) var(--border-radius) 0;
- }
-
- .hidden-file-input {
- display: none;
- }
-
- .token-textarea {
- resize: vertical;
- min-height: 80px;
- font-size: 11.5px;
- font-family: var(--font-mono);
- line-height: 1.5;
- }
-
- .form {
- display: flex;
- flex-direction: column;
- gap: var(--padding);
- }
-
- .field {
- display: flex;
- flex-direction: column;
- gap: calc(var(--padding) / 2);
- }
-
- .field-label {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .input {
- width: 100%;
- padding: var(--padding);
- font-size: 14.5px;
- background: var(--button);
- border-radius: var(--border-radius);
- color: var(--secondary);
- border: 1px solid var(--input-border);
- }
-
- .input::placeholder {
- color: var(--gray);
- }
-
- .input:focus-visible {
- border-color: var(--secondary);
- outline: none;
- }
-
- .input:disabled {
- opacity: 0.5;
- cursor: default;
- }
-
- .error-msg {
- color: var(--red);
- font-size: 12.5px;
- font-weight: 500;
- }
-
- .spinner-section {
- display: flex;
- flex-direction: column;
- align-items: center;
- gap: var(--padding);
- padding: calc(var(--padding) * 4) 0;
- }
-
- .spinner {
- width: 24px;
- height: 24px;
- border: 2px solid var(--input-border);
- border-top-color: var(--blue);
- border-radius: 50%;
- animation: spin 0.6s linear infinite;
- }
-
- @keyframes spin {
- to {
- transform: rotate(360deg);
- }
- }
-
- .spinner-text {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .error-section {
- display: flex;
- flex-direction: column;
- align-items: center;
- gap: var(--padding);
- padding: calc(var(--padding) * 2) 0;
- }
-
- .empty-text {
- color: var(--gray);
- font-size: 14.5px;
- text-align: center;
- padding: calc(var(--padding) * 4) 0;
- }
-</style>
diff --git a/src/routes/courses/masterclass/+page.svelte b/src/routes/courses/masterclass/+page.svelte
deleted file mode 100644
index cc214f84..00000000
--- a/src/routes/courses/masterclass/+page.svelte
+++ /dev/null
@@ -1,601 +0,0 @@
-<script lang="ts">
- import { pluginInvoke } from "$lib/plugin-invoke";
- import { open } from "@tauri-apps/plugin-dialog";
- import CourseCard from "$components/hotmart/CourseCard.svelte";
- import { showToast } from "$lib/stores/toast-store.svelte";
- import { getDownloads } from "$lib/stores/download-store.svelte";
- import { getSettings } from "$lib/stores/settings-store.svelte";
- import { t } from "$lib/i18n";
-
- let downloads = $derived(getDownloads());
-
- type MasterClassCourse = {
- id: string;
- name: string;
- instructor: string;
- slug: string;
- };
-
- let cookies = $state("");
- let fileInput: HTMLInputElement = $state() as HTMLInputElement;
- function onFileSelected(e: Event) {
- const input = e.target as HTMLInputElement;
- const file = input.files?.[0];
- if (!file) return;
- const reader = new FileReader();
- reader.onload = () => { cookies = reader.result as string; };
- reader.readAsText(file);
- input.value = "";
- }
- let loading = $state(false);
- let error = $state("");
-
- let checking = $state(true);
- let loggedIn = $state(false);
-
- let courses: MasterClassCourse[] = $state([]);
- let loadingCourses = $state(false);
- let coursesError = $state("");
-
- const ITEMS_PER_PAGE = 12;
- let currentPage = $state(1);
-
- let totalPages = $derived(Math.max(1, Math.ceil(courses.length / ITEMS_PER_PAGE)));
- let paginatedCourses = $derived(
- courses.slice((currentPage - 1) * ITEMS_PER_PAGE, currentPage * ITEMS_PER_PAGE)
- );
-
- let pageNumbers = $derived((): number[] => {
- const pages: number[] = [];
- if (totalPages <= 7) {
- for (let i = 1; i <= totalPages; i++) pages.push(i);
- } else {
- pages.push(1);
- if (currentPage > 3) pages.push(-1);
- const start = Math.max(2, currentPage - 1);
- const end = Math.min(totalPages - 1, currentPage + 1);
- for (let i = start; i <= end; i++) pages.push(i);
- if (currentPage < totalPages - 2) pages.push(-1);
- pages.push(totalPages);
- }
- return pages;
- });
-
- function goToPage(page: number) {
- if (page >= 1 && page <= totalPages) {
- currentPage = page;
- }
- }
-
- $effect(() => {
- checkSession();
- });
-
- async function checkSession() {
- try {
- await pluginInvoke<string>("courses", "masterclass_check_session");
- loggedIn = true;
- loadCourses();
- } catch {
- loggedIn = false;
- } finally {
- checking = false;
- }
- }
-
- async function handleCookieLogin() {
- if (!cookies.trim()) return;
- error = "";
- loading = true;
- try {
- await pluginInvoke<string>("courses", "masterclass_login_cookies", { cookies: cookies.trim() });
- loggedIn = true;
- loadCourses();
- } catch (e: any) {
- error = typeof e === "string" ? e : e.message ?? $t('hotmart.unknown_error');
- } finally {
- loading = false;
- }
- }
-
- async function handleLogout() {
- try {
- await pluginInvoke("courses", "masterclass_logout");
- } catch {
- }
- loggedIn = false;
- courses = [];
- coursesError = "";
- currentPage = 1;
- }
-
- async function loadCourses() {
- loadingCourses = true;
- coursesError = "";
- try {
- courses = await pluginInvoke("courses", "masterclass_list_courses");
- currentPage = 1;
- } catch (e: any) {
- coursesError = typeof e === "string" ? e : e.message ?? $t('hotmart.courses_error');
- } finally {
- loadingCourses = false;
- }
- }
-
- function getCourseDownloadStatus(courseId: string): "idle" | "downloading" | "complete" | "error" {
- const hash = hashString(courseId);
- const item = downloads.get(hash);
- if (!item) return "idle";
- const s = item.status;
- if (s === "queued" || s === "paused" || s === "seeding") return "downloading";
- return s;
- }
-
- function getCourseDownloadPercent(courseId: string): number {
- return downloads.get(hashString(courseId))?.percent ?? 0;
- }
-
- function hashString(str: string): number {
- let hash = 0;
- for (let i = 0; i < str.length; i++) {
- const char = str.charCodeAt(i);
- hash = ((hash << 5) - hash) + char;
- hash |= 0;
- }
- return Math.abs(hash);
- }
-
- async function downloadCourse(course: MasterClassCourse) {
- const status = getCourseDownloadStatus(course.id);
- if (status === "downloading") {
- showToast("info", $t("toast.download_already_active"));
- return;
- }
- if (status === "complete") return;
-
- const appSettings = getSettings();
- let outputDir: string | null = null;
-
- if (appSettings?.download.always_ask_path) {
- outputDir = await open({ directory: true, title: $t("hotmart.choose_folder") }) as string | null;
- if (!outputDir) return;
- } else {
- outputDir = appSettings?.download.default_output_dir ?? null;
- if (!outputDir) {
- outputDir = await open({ directory: true, title: $t("hotmart.choose_folder") }) as string | null;
- if (!outputDir) return;
- }
- }
-
- try {
- await pluginInvoke("courses", "start_masterclass_course_download", {
- courseJson: JSON.stringify(course),
- outputDir,
- });
- showToast("info", $t("toast.download_preparing"));
- } catch (e: any) {
- const msg = typeof e === "string" ? e : e.message ?? $t("common.error");
- showToast("error", msg);
- }
- }
-
- let refreshing = $state(false);
-
- async function refreshCourses() {
- refreshing = true;
- loadingCourses = true;
- coursesError = "";
- try {
- courses = await pluginInvoke("courses", "masterclass_refresh_courses");
- currentPage = 1;
- } catch (e: any) {
- coursesError = typeof e === "string" ? e : e.message ?? $t('hotmart.courses_error');
- } finally {
- loadingCourses = false;
- refreshing = false;
- }
- }
-</script>
-
-<a href="/courses" class="back-link">
- <svg viewBox="0 0 24 24" width="16" height="16" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
- <path d="M19 12H5" />
- <path d="M12 19l-7-7 7-7" />
- </svg>
- {$t("courses.back")}
-</a>
-
-{#if checking}
- <div class="page-center">
- <span class="spinner"></span>
- <span class="spinner-text">{$t('hotmart.checking_session')}</span>
- </div>
-{:else if loggedIn}
- <div class="page-logged">
- <div class="session-bar">
- <span class="session-info">MasterClass</span>
- <div class="session-actions">
- <button
- class="button"
- onclick={refreshCourses}
- disabled={refreshing}
- aria-label={$t('hotmart.refresh')}
- >
- <svg viewBox="0 0 24 24" width="14" height="14" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class:spinning={refreshing}>
- <path d="M21 2v6h-6" />
- <path d="M3 12a9 9 0 0115-6.7L21 8" />
- <path d="M3 22v-6h6" />
- <path d="M21 12a9 9 0 01-15 6.7L3 16" />
- </svg>
- </button>
- <button class="button" onclick={handleLogout}>{$t('hotmart.logout')}</button>
- </div>
- </div>
-
- {#if loadingCourses}
- <div class="spinner-section">
- <span class="spinner"></span>
- <span class="spinner-text">{$t('hotmart.loading_courses')}</span>
- </div>
- {:else if coursesError}
- <div class="error-section">
- <p class="error-msg">{coursesError}</p>
- <button class="button" onclick={loadCourses}>{$t('common.retry')}</button>
- </div>
- {:else if courses.length === 0}
- <p class="empty-text">{$t('hotmart.no_courses')}</p>
- {:else}
- <div class="courses-header">
- <h2>{$t('hotmart.courses_title')}</h2>
- <span class="subtext">{courses.length === 1 ? $t('hotmart.course_count_one', { count: courses.length }) : $t('hotmart.course_count', { count: courses.length })}</span>
- </div>
-
- <div class="courses-grid">
- {#each paginatedCourses as course (course.id)}
- <CourseCard
- name={course.instructor ? `${course.instructor} - ${course.name}` : course.name}
- price=""
- downloadStatus={getCourseDownloadStatus(course.id)}
- downloadPercent={getCourseDownloadPercent(course.id)}
- onDownload={() => downloadCourse(course)}
- />
- {/each}
- </div>
-
- {#if totalPages > 1}
- <div class="pagination">
- <span class="pagination-info">
- {$t('hotmart.page_of', { current: currentPage, total: totalPages })} &middot; {courses.length === 1 ? $t('hotmart.course_count_one', { count: courses.length }) : $t('hotmart.course_count', { count: courses.length })}
- </span>
- <div class="pagination-controls">
- <button
- class="button pagination-btn"
- disabled={currentPage <= 1}
- onclick={() => goToPage(currentPage - 1)}
- >
- &lt;
- </button>
-
- {#each pageNumbers() as page}
- {#if page === -1}
- <span class="pagination-ellipsis">&hellip;</span>
- {:else}
- <button
- class="button pagination-btn"
- class:active={page === currentPage}
- onclick={() => goToPage(page)}
- >
- {page}
- </button>
- {/if}
- {/each}
-
- <button
- class="button pagination-btn"
- disabled={currentPage >= totalPages}
- onclick={() => goToPage(currentPage + 1)}
- >
- &gt;
- </button>
- </div>
- </div>
- {/if}
- {/if}
- </div>
-{:else}
- <div class="page-center">
- <div class="login-card">
- <h2>MasterClass</h2>
-
- <div class="form">
- <label class="field">
- <span class="field-label">Cookies JSON</span>
- <textarea
- class="input token-textarea"
- placeholder="Paste cookies JSON from browser extension or a raw token"
- bind:value={cookies}
- disabled={loading}
- rows="4"
- ></textarea>
- </label>
- <input type="file" accept=".json,.txt" class="hidden-file-input" bind:this={fileInput} onchange={onFileSelected} />
- <button class="button" onclick={() => fileInput?.click()} disabled={loading}>Import .json file</button>
-
- {#if error}
- <p class="error-msg">{error}</p>
- {/if}
-
- <button class="button" onclick={handleCookieLogin} disabled={loading || !cookies.trim()}>
- {#if loading}
- {$t('hotmart.authenticating')}
- {:else}
- {$t('hotmart.login')}
- {/if}
- </button>
- </div>
- </div>
- </div>
-{/if}
-
-<style>
- .back-link {
- display: inline-flex;
- align-items: center;
- gap: 6px;
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- margin-bottom: var(--padding);
- }
-
- @media (hover: hover) {
- .back-link:hover {
- color: var(--secondary);
- }
- }
-
- .page-center {
- display: flex;
- flex-direction: column;
- align-items: center;
- justify-content: center;
- min-height: calc(100vh - var(--padding) * 4 - 40px);
- gap: var(--padding);
- }
-
- .page-logged {
- display: flex;
- flex-direction: column;
- align-items: center;
- gap: calc(var(--padding) * 1.5);
- padding: calc(var(--padding) * 1.5);
- width: 100%;
- }
-
- .page-logged > :global(*) {
- width: 100%;
- max-width: 1200px;
- }
-
- .session-bar {
- display: flex;
- align-items: center;
- justify-content: space-between;
- }
-
- .session-info {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .session-actions {
- display: flex;
- gap: calc(var(--padding) / 2);
- }
-
- .session-bar :global(.button) {
- padding: calc(var(--padding) / 2) var(--padding);
- font-size: 12.5px;
- }
-
- .spinning {
- animation: spin 0.6s linear infinite;
- }
-
- .courses-header {
- display: flex;
- align-items: baseline;
- gap: var(--padding);
- }
-
- .courses-header h2 {
- margin-block: 0;
- }
-
- .subtext {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .courses-grid {
- display: grid;
- grid-template-columns: repeat(4, 1fr);
- gap: var(--padding);
- }
-
- @media (max-width: 1000px) {
- .courses-grid {
- grid-template-columns: repeat(3, 1fr);
- }
- }
-
- @media (max-width: 750px) {
- .courses-grid {
- grid-template-columns: repeat(2, 1fr);
- }
- }
-
- @media (max-width: 535px) {
- .courses-grid {
- grid-template-columns: 1fr;
- }
- }
-
- .pagination {
- display: flex;
- flex-direction: column;
- align-items: center;
- gap: var(--padding);
- padding-top: var(--padding);
- }
-
- .pagination-info {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .pagination-controls {
- display: flex;
- align-items: center;
- gap: calc(var(--padding) / 3);
- }
-
- .pagination-btn {
- min-width: 36px;
- height: 36px;
- padding: 0;
- display: flex;
- align-items: center;
- justify-content: center;
- font-size: 14.5px;
- }
-
- .pagination-ellipsis {
- min-width: 36px;
- text-align: center;
- color: var(--gray);
- font-size: 14.5px;
- }
-
- .login-card {
- width: 100%;
- max-width: 400px;
- background: var(--button-elevated);
- border-radius: var(--border-radius);
- padding: calc(var(--padding) * 2);
- display: flex;
- flex-direction: column;
- gap: calc(var(--padding) * 1.5);
- }
-
- .login-card h2 {
- margin-block: 0;
- }
-
- .hidden-file-input {
- display: none;
- }
-
- .token-textarea {
- resize: vertical;
- min-height: 80px;
- font-size: 11.5px;
- font-family: var(--font-mono);
- line-height: 1.5;
- }
-
- .form {
- display: flex;
- flex-direction: column;
- gap: var(--padding);
- }
-
- .field {
- display: flex;
- flex-direction: column;
- gap: calc(var(--padding) / 2);
- }
-
- .field-label {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .input {
- width: 100%;
- padding: var(--padding);
- font-size: 14.5px;
- background: var(--button);
- border-radius: var(--border-radius);
- color: var(--secondary);
- border: 1px solid var(--input-border);
- }
-
- .input::placeholder {
- color: var(--gray);
- }
-
- .input:focus-visible {
- border-color: var(--secondary);
- outline: none;
- }
-
- .input:disabled {
- opacity: 0.5;
- cursor: default;
- }
-
- .error-msg {
- color: var(--red);
- font-size: 12.5px;
- font-weight: 500;
- }
-
- .spinner-section {
- display: flex;
- flex-direction: column;
- align-items: center;
- gap: var(--padding);
- padding: calc(var(--padding) * 4) 0;
- }
-
- .spinner {
- width: 24px;
- height: 24px;
- border: 2px solid var(--input-border);
- border-top-color: var(--blue);
- border-radius: 50%;
- animation: spin 0.6s linear infinite;
- }
-
- @keyframes spin {
- to {
- transform: rotate(360deg);
- }
- }
-
- .spinner-text {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .error-section {
- display: flex;
- flex-direction: column;
- align-items: center;
- gap: var(--padding);
- padding: calc(var(--padding) * 2) 0;
- }
-
- .empty-text {
- color: var(--gray);
- font-size: 14.5px;
- text-align: center;
- padding: calc(var(--padding) * 4) 0;
- }
-</style>
diff --git a/src/routes/courses/medcel/+page.svelte b/src/routes/courses/medcel/+page.svelte
deleted file mode 100644
index a54ada4c..00000000
--- a/src/routes/courses/medcel/+page.svelte
+++ /dev/null
@@ -1,726 +0,0 @@
-<script lang="ts">
- import { pluginInvoke } from "$lib/plugin-invoke";
- import { open } from "@tauri-apps/plugin-dialog";
- import CourseCard from "$components/hotmart/CourseCard.svelte";
- import { showToast } from "$lib/stores/toast-store.svelte";
- import { getDownloads } from "$lib/stores/download-store.svelte";
- import { getSettings } from "$lib/stores/settings-store.svelte";
- import { t } from "$lib/i18n";
-
- let downloads = $derived(getDownloads());
-
- type MedcelCourse = {
- id: string;
- name: string;
- product_id: string;
- };
-
- let email = $state("");
- let password = $state("");
- let token = $state("");
- let apiKey = $state("");
- let loading = $state(false);
- let error = $state("");
-
- let checking = $state(true);
- let loggedIn = $state(false);
- let sessionEmail = $state("");
-
- let loginMode = $state<"credentials" | "token">("credentials");
-
- let fileInput: HTMLInputElement = $state() as HTMLInputElement;
-
- function onFileSelected(e: Event) {
- const input = e.target as HTMLInputElement;
- const file = input.files?.[0];
- if (!file) return;
- const reader = new FileReader();
- reader.onload = () => { token = reader.result as string; };
- reader.readAsText(file);
- input.value = "";
- }
-
- let courses: MedcelCourse[] = $state([]);
- let loadingCourses = $state(false);
- let coursesError = $state("");
-
- const ITEMS_PER_PAGE = 12;
- let currentPage = $state(1);
-
- let totalPages = $derived(Math.max(1, Math.ceil(courses.length / ITEMS_PER_PAGE)));
- let paginatedCourses = $derived(
- courses.slice((currentPage - 1) * ITEMS_PER_PAGE, currentPage * ITEMS_PER_PAGE)
- );
-
- let pageNumbers = $derived((): number[] => {
- const pages: number[] = [];
- if (totalPages <= 7) {
- for (let i = 1; i <= totalPages; i++) pages.push(i);
- } else {
- pages.push(1);
- if (currentPage > 3) pages.push(-1);
- const start = Math.max(2, currentPage - 1);
- const end = Math.min(totalPages - 1, currentPage + 1);
- for (let i = start; i <= end; i++) pages.push(i);
- if (currentPage < totalPages - 2) pages.push(-1);
- pages.push(totalPages);
- }
- return pages;
- });
-
- function goToPage(page: number) {
- if (page >= 1 && page <= totalPages) {
- currentPage = page;
- }
- }
-
- $effect(() => {
- checkSession();
- });
-
- async function checkSession() {
- try {
- const result = await pluginInvoke<string>("courses", "medcel_check_session");
- sessionEmail = result;
- loggedIn = true;
- loadCourses();
- } catch {
- loggedIn = false;
- } finally {
- checking = false;
- }
- }
-
- async function handleLogin() {
- error = "";
- loading = true;
- try {
- const result = await pluginInvoke<string>("courses", "medcel_login", { email, password, apiKey });
- sessionEmail = result || email;
- loggedIn = true;
- loadCourses();
- } catch (e: any) {
- error = typeof e === "string" ? e : e.message ?? $t('hotmart.unknown_error');
- } finally {
- loading = false;
- }
- }
-
- async function handleTokenLogin() {
- if (!token.trim()) return;
- error = "";
- loading = true;
- try {
- const result = await pluginInvoke<string>("courses", "medcel_login_token", { token: token.trim(), apiKey });
- sessionEmail = result || "Token";
- loggedIn = true;
- loadCourses();
- } catch (e: any) {
- error = typeof e === "string" ? e : e.message ?? $t('hotmart.unknown_error');
- } finally {
- loading = false;
- }
- }
-
- async function handleLogout() {
- try {
- await pluginInvoke("courses", "medcel_logout");
- } catch {
- }
- loggedIn = false;
- sessionEmail = "";
- courses = [];
- coursesError = "";
- currentPage = 1;
- }
-
- async function loadCourses() {
- loadingCourses = true;
- coursesError = "";
- try {
- courses = await pluginInvoke("courses", "medcel_list_courses");
- currentPage = 1;
- } catch (e: any) {
- coursesError = typeof e === "string" ? e : e.message ?? $t('hotmart.courses_error');
- } finally {
- loadingCourses = false;
- }
- }
-
- function getCourseDownloadStatus(courseId: number): "idle" | "downloading" | "complete" | "error" {
- const item = downloads.get(courseId);
- if (!item) return "idle";
- const s = item.status;
- if (s === "queued" || s === "paused" || s === "seeding") return "downloading";
- return s;
- }
-
- function getCourseDownloadPercent(courseId: number): number {
- return downloads.get(courseId)?.percent ?? 0;
- }
-
- async function downloadCourse(course: MedcelCourse) {
- const status = getCourseDownloadStatus(Number(course.id) || 0);
- if (status === "downloading") {
- showToast("info", $t("toast.download_already_active"));
- return;
- }
- if (status === "complete") return;
-
- const appSettings = getSettings();
- let outputDir: string | null = null;
-
- if (appSettings?.download.always_ask_path) {
- outputDir = await open({ directory: true, title: $t("hotmart.choose_folder") }) as string | null;
- if (!outputDir) return;
- } else {
- outputDir = appSettings?.download.default_output_dir ?? null;
- if (!outputDir) {
- outputDir = await open({ directory: true, title: $t("hotmart.choose_folder") }) as string | null;
- if (!outputDir) return;
- }
- }
-
- try {
- await pluginInvoke("courses", "start_medcel_course_download", {
- courseJson: JSON.stringify(course),
- outputDir,
- });
- showToast("info", $t("toast.download_preparing"));
- } catch (e: any) {
- const msg = typeof e === "string" ? e : e.message ?? $t("common.error");
- showToast("error", msg);
- }
- }
-
- let refreshing = $state(false);
-
- async function refreshCourses() {
- refreshing = true;
- loadingCourses = true;
- coursesError = "";
- try {
- courses = await pluginInvoke("courses", "medcel_refresh_courses");
- currentPage = 1;
- } catch (e: any) {
- coursesError = typeof e === "string" ? e : e.message ?? $t('hotmart.courses_error');
- } finally {
- loadingCourses = false;
- refreshing = false;
- }
- }
-</script>
-
-<a href="/courses" class="back-link">
- <svg viewBox="0 0 24 24" width="16" height="16" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
- <path d="M19 12H5" />
- <path d="M12 19l-7-7 7-7" />
- </svg>
- {$t("courses.back")}
-</a>
-
-{#if checking}
- <div class="page-center">
- <span class="spinner"></span>
- <span class="spinner-text">{$t('hotmart.checking_session')}</span>
- </div>
-{:else if loggedIn}
- <div class="page-logged">
- <div class="session-bar">
- <span class="session-info">
- {$t('hotmart.logged_as', { email: sessionEmail || "—" })}
- </span>
- <div class="session-actions">
- <button
- class="button"
- onclick={refreshCourses}
- disabled={refreshing}
- aria-label={$t('hotmart.refresh')}
- >
- <svg viewBox="0 0 24 24" width="14" height="14" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class:spinning={refreshing}>
- <path d="M21 2v6h-6" />
- <path d="M3 12a9 9 0 0115-6.7L21 8" />
- <path d="M3 22v-6h6" />
- <path d="M21 12a9 9 0 01-15 6.7L3 16" />
- </svg>
- </button>
- <button class="button" onclick={handleLogout}>{$t('hotmart.logout')}</button>
- </div>
- </div>
-
- {#if loadingCourses}
- <div class="spinner-section">
- <span class="spinner"></span>
- <span class="spinner-text">{$t('hotmart.loading_courses')}</span>
- </div>
- {:else if coursesError}
- <div class="error-section">
- <p class="error-msg">{coursesError}</p>
- <button class="button" onclick={loadCourses}>{$t('common.retry')}</button>
- </div>
- {:else if courses.length === 0}
- <p class="empty-text">{$t('hotmart.no_courses')}</p>
- {:else}
- <div class="courses-header">
- <h2>{$t('hotmart.courses_title')}</h2>
- <span class="subtext">{courses.length === 1 ? $t('hotmart.course_count_one', { count: courses.length }) : $t('hotmart.course_count', { count: courses.length })}</span>
- </div>
-
- <div class="courses-grid">
- {#each paginatedCourses as course (course.id)}
- <CourseCard
- name={course.name}
- price=""
- imageUrl={undefined}
- downloadStatus={getCourseDownloadStatus(Number(course.id) || 0)}
- downloadPercent={getCourseDownloadPercent(Number(course.id) || 0)}
- onDownload={() => downloadCourse(course)}
- />
- {/each}
- </div>
-
- {#if totalPages > 1}
- <div class="pagination">
- <span class="pagination-info">
- {$t('hotmart.page_of', { current: currentPage, total: totalPages })} &middot; {courses.length === 1 ? $t('hotmart.course_count_one', { count: courses.length }) : $t('hotmart.course_count', { count: courses.length })}
- </span>
- <div class="pagination-controls">
- <button
- class="button pagination-btn"
- disabled={currentPage <= 1}
- onclick={() => goToPage(currentPage - 1)}
- >
- &lt;
- </button>
-
- {#each pageNumbers() as page}
- {#if page === -1}
- <span class="pagination-ellipsis">&hellip;</span>
- {:else}
- <button
- class="button pagination-btn"
- class:active={page === currentPage}
- onclick={() => goToPage(page)}
- >
- {page}
- </button>
- {/if}
- {/each}
-
- <button
- class="button pagination-btn"
- disabled={currentPage >= totalPages}
- onclick={() => goToPage(currentPage + 1)}
- >
- &gt;
- </button>
- </div>
- </div>
- {/if}
- {/if}
- </div>
-{:else}
- <div class="page-center">
- <div class="login-card">
- <h2>Medcel</h2>
-
- <div class="login-tabs">
- <button
- class="button login-tab"
- class:active={loginMode === "credentials"}
- onclick={() => { loginMode = "credentials"; error = ""; }}
- >
- Email & Password
- </button>
- <button
- class="button login-tab"
- class:active={loginMode === "token"}
- onclick={() => { loginMode = "token"; error = ""; }}
- >
- Token
- </button>
- </div>
-
- {#if loginMode === "credentials"}
- <form class="form" onsubmit={(e) => { e.preventDefault(); handleLogin(); }}>
- <label class="field">
- <span class="field-label">{$t('hotmart.email_label')}</span>
- <input
- type="email"
- placeholder={$t('hotmart.email_placeholder')}
- bind:value={email}
- class="input"
- disabled={loading}
- required
- />
- </label>
- <label class="field">
- <span class="field-label">{$t('hotmart.password_label')}</span>
- <input
- type="password"
- placeholder={$t('hotmart.password_placeholder')}
- bind:value={password}
- class="input"
- disabled={loading}
- required
- />
- </label>
- <label class="field">
- <span class="field-label">X-API-Key</span>
- <input
- type="text"
- placeholder="Enter your API key..."
- bind:value={apiKey}
- class="input"
- disabled={loading}
- required
- />
- </label>
-
- {#if error}
- <p class="error-msg">{error}</p>
- {/if}
-
- <button type="submit" class="button" disabled={loading}>
- {#if loading}
- {$t('hotmart.authenticating')}
- {:else}
- {$t('hotmart.login')}
- {/if}
- </button>
- </form>
- {:else}
- <div class="form">
- <label class="field">
- <span class="field-label">Cookies JSON</span>
- <textarea
- class="input token-textarea"
- placeholder="Paste cookies JSON from browser extension or a raw token"
- bind:value={token}
- disabled={loading}
- rows="5"
- ></textarea>
- </label>
-
- <input
- type="file"
- accept=".json,.txt"
- class="hidden-file-input"
- bind:this={fileInput}
- onchange={onFileSelected}
- />
- <button class="button" onclick={() => fileInput?.click()} disabled={loading}>
- Import .json file
- </button>
-
- <label class="field">
- <span class="field-label">X-API-Key</span>
- <input
- type="text"
- placeholder="Enter your API key..."
- bind:value={apiKey}
- class="input"
- disabled={loading}
- required
- />
- </label>
-
- {#if error}
- <p class="error-msg">{error}</p>
- {/if}
-
- <button class="button" onclick={handleTokenLogin} disabled={loading || !token.trim()}>
- {#if loading}
- {$t('hotmart.authenticating')}
- {:else}
- {$t('hotmart.login')}
- {/if}
- </button>
- </div>
- {/if}
- </div>
- </div>
-{/if}
-
-<style>
- .back-link {
- display: inline-flex;
- align-items: center;
- gap: 6px;
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- margin-bottom: var(--padding);
- }
-
- @media (hover: hover) {
- .back-link:hover {
- color: var(--secondary);
- }
- }
-
- .page-center {
- display: flex;
- flex-direction: column;
- align-items: center;
- justify-content: center;
- min-height: calc(100vh - var(--padding) * 4 - 40px);
- gap: var(--padding);
- }
-
- .page-logged {
- display: flex;
- flex-direction: column;
- align-items: center;
- gap: calc(var(--padding) * 1.5);
- padding: calc(var(--padding) * 1.5);
- width: 100%;
- }
-
- .page-logged > :global(*) {
- width: 100%;
- max-width: 1200px;
- }
-
- .session-bar {
- display: flex;
- align-items: center;
- justify-content: space-between;
- }
-
- .session-info {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .session-actions {
- display: flex;
- gap: calc(var(--padding) / 2);
- }
-
- .session-bar :global(.button) {
- padding: calc(var(--padding) / 2) var(--padding);
- font-size: 12.5px;
- }
-
- .spinning {
- animation: spin 0.6s linear infinite;
- }
-
- .courses-header {
- display: flex;
- align-items: baseline;
- gap: var(--padding);
- }
-
- .courses-header h2 {
- margin-block: 0;
- }
-
- .subtext {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .courses-grid {
- display: grid;
- grid-template-columns: repeat(4, 1fr);
- gap: var(--padding);
- }
-
- @media (max-width: 1000px) {
- .courses-grid {
- grid-template-columns: repeat(3, 1fr);
- }
- }
-
- @media (max-width: 750px) {
- .courses-grid {
- grid-template-columns: repeat(2, 1fr);
- }
- }
-
- @media (max-width: 535px) {
- .courses-grid {
- grid-template-columns: 1fr;
- }
- }
-
- .pagination {
- display: flex;
- flex-direction: column;
- align-items: center;
- gap: var(--padding);
- padding-top: var(--padding);
- }
-
- .pagination-info {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .pagination-controls {
- display: flex;
- align-items: center;
- gap: calc(var(--padding) / 3);
- }
-
- .pagination-btn {
- min-width: 36px;
- height: 36px;
- padding: 0;
- display: flex;
- align-items: center;
- justify-content: center;
- font-size: 14.5px;
- }
-
- .pagination-ellipsis {
- min-width: 36px;
- text-align: center;
- color: var(--gray);
- font-size: 14.5px;
- }
-
- .login-card {
- width: 100%;
- max-width: 400px;
- background: var(--button-elevated);
- border-radius: var(--border-radius);
- padding: calc(var(--padding) * 2);
- display: flex;
- flex-direction: column;
- gap: calc(var(--padding) * 1.5);
- }
-
- .login-card h2 {
- margin-block: 0;
- }
-
- .login-tabs {
- display: flex;
- gap: 0;
- }
-
- .login-tab {
- flex: 1;
- border-radius: 0;
- font-size: 12.5px;
- padding: calc(var(--padding) * 0.75) var(--padding);
- }
-
- .login-tab:first-child {
- border-radius: var(--border-radius) 0 0 var(--border-radius);
- }
-
- .login-tab:last-child {
- border-radius: 0 var(--border-radius) var(--border-radius) 0;
- }
-
- .hidden-file-input {
- display: none;
- }
-
- .token-textarea {
- resize: vertical;
- min-height: 80px;
- font-size: 11.5px;
- font-family: var(--font-mono);
- line-height: 1.5;
- }
-
- .form {
- display: flex;
- flex-direction: column;
- gap: var(--padding);
- }
-
- .field {
- display: flex;
- flex-direction: column;
- gap: calc(var(--padding) / 2);
- }
-
- .field-label {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .input {
- width: 100%;
- padding: var(--padding);
- font-size: 14.5px;
- background: var(--button);
- border-radius: var(--border-radius);
- color: var(--secondary);
- border: 1px solid var(--input-border);
- }
-
- .input::placeholder {
- color: var(--gray);
- }
-
- .input:focus-visible {
- border-color: var(--secondary);
- outline: none;
- }
-
- .input:disabled {
- opacity: 0.5;
- cursor: default;
- }
-
- .error-msg {
- color: var(--red);
- font-size: 12.5px;
- font-weight: 500;
- }
-
- .spinner-section {
- display: flex;
- flex-direction: column;
- align-items: center;
- gap: var(--padding);
- padding: calc(var(--padding) * 4) 0;
- }
-
- .spinner {
- width: 24px;
- height: 24px;
- border: 2px solid var(--input-border);
- border-top-color: var(--blue);
- border-radius: 50%;
- animation: spin 0.6s linear infinite;
- }
-
- @keyframes spin {
- to {
- transform: rotate(360deg);
- }
- }
-
- .spinner-text {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .error-section {
- display: flex;
- flex-direction: column;
- align-items: center;
- gap: var(--padding);
- padding: calc(var(--padding) * 2) 0;
- }
-
- .empty-text {
- color: var(--gray);
- font-size: 14.5px;
- text-align: center;
- padding: calc(var(--padding) * 4) 0;
- }
-</style>
diff --git a/src/routes/courses/medcof/+page.svelte b/src/routes/courses/medcof/+page.svelte
deleted file mode 100644
index f98ac97a..00000000
--- a/src/routes/courses/medcof/+page.svelte
+++ /dev/null
@@ -1,596 +0,0 @@
-<script lang="ts">
- import { pluginInvoke } from "$lib/plugin-invoke";
- import { open } from "@tauri-apps/plugin-dialog";
- import CourseCard from "$components/hotmart/CourseCard.svelte";
- import { showToast } from "$lib/stores/toast-store.svelte";
- import { getDownloads } from "$lib/stores/download-store.svelte";
- import { getSettings } from "$lib/stores/settings-store.svelte";
- import { t } from "$lib/i18n";
-
- let downloads = $derived(getDownloads());
-
- type MedcofCourse = {
- id: string;
- name: string;
- };
-
- let token = $state("");
- let fileInput: HTMLInputElement = $state() as HTMLInputElement;
- function onFileSelected(e: Event) {
- const input = e.target as HTMLInputElement;
- const file = input.files?.[0];
- if (!file) return;
- const reader = new FileReader();
- reader.onload = () => { token = reader.result as string; };
- reader.readAsText(file);
- input.value = "";
- }
- let loading = $state(false);
- let error = $state("");
-
- let checking = $state(true);
- let loggedIn = $state(false);
- let sessionEmail = $state("");
-
- let courses: MedcofCourse[] = $state([]);
- let loadingCourses = $state(false);
- let coursesError = $state("");
-
- const ITEMS_PER_PAGE = 12;
- let currentPage = $state(1);
-
- let totalPages = $derived(Math.max(1, Math.ceil(courses.length / ITEMS_PER_PAGE)));
- let paginatedCourses = $derived(
- courses.slice((currentPage - 1) * ITEMS_PER_PAGE, currentPage * ITEMS_PER_PAGE)
- );
-
- let pageNumbers = $derived((): number[] => {
- const pages: number[] = [];
- if (totalPages <= 7) {
- for (let i = 1; i <= totalPages; i++) pages.push(i);
- } else {
- pages.push(1);
- if (currentPage > 3) pages.push(-1);
- const start = Math.max(2, currentPage - 1);
- const end = Math.min(totalPages - 1, currentPage + 1);
- for (let i = start; i <= end; i++) pages.push(i);
- if (currentPage < totalPages - 2) pages.push(-1);
- pages.push(totalPages);
- }
- return pages;
- });
-
- function goToPage(page: number) {
- if (page >= 1 && page <= totalPages) {
- currentPage = page;
- }
- }
-
- $effect(() => {
- checkSession();
- });
-
- async function checkSession() {
- try {
- const result = await pluginInvoke<string>("courses", "medcof_check_session");
- sessionEmail = result;
- loggedIn = true;
- loadCourses();
- } catch {
- loggedIn = false;
- } finally {
- checking = false;
- }
- }
-
- async function handleTokenLogin() {
- if (!token.trim()) return;
- error = "";
- loading = true;
- try {
- const result = await pluginInvoke<string>("courses", "medcof_login_token", { token: token.trim() });
- sessionEmail = result || "Token";
- loggedIn = true;
- loadCourses();
- } catch (e: any) {
- error = typeof e === "string" ? e : e.message ?? $t('hotmart.unknown_error');
- } finally {
- loading = false;
- }
- }
-
- async function handleLogout() {
- try {
- await pluginInvoke("courses", "medcof_logout");
- } catch {
- }
- loggedIn = false;
- sessionEmail = "";
- courses = [];
- coursesError = "";
- currentPage = 1;
- }
-
- async function loadCourses() {
- loadingCourses = true;
- coursesError = "";
- try {
- courses = await pluginInvoke("courses", "medcof_list_courses");
- currentPage = 1;
- } catch (e: any) {
- coursesError = typeof e === "string" ? e : e.message ?? $t('hotmart.courses_error');
- } finally {
- loadingCourses = false;
- }
- }
-
- function getCourseDownloadStatus(courseId: string): "idle" | "downloading" | "complete" | "error" {
- const numId = Number(courseId) || 0;
- const item = downloads.get(numId);
- if (!item) return "idle";
- const s = item.status;
- if (s === "queued" || s === "paused" || s === "seeding") return "downloading";
- return s;
- }
-
- function getCourseDownloadPercent(courseId: string): number {
- const numId = Number(courseId) || 0;
- return downloads.get(numId)?.percent ?? 0;
- }
-
- async function downloadCourse(course: MedcofCourse) {
- const status = getCourseDownloadStatus(course.id);
- if (status === "downloading") {
- showToast("info", $t("toast.download_already_active"));
- return;
- }
- if (status === "complete") return;
-
- const appSettings = getSettings();
- let outputDir: string | null = null;
-
- if (appSettings?.download.always_ask_path) {
- outputDir = await open({ directory: true, title: $t("hotmart.choose_folder") }) as string | null;
- if (!outputDir) return;
- } else {
- outputDir = appSettings?.download.default_output_dir ?? null;
- if (!outputDir) {
- outputDir = await open({ directory: true, title: $t("hotmart.choose_folder") }) as string | null;
- if (!outputDir) return;
- }
- }
-
- try {
- await pluginInvoke("courses", "start_medcof_download", {
- courseJson: JSON.stringify(course),
- outputDir,
- });
- showToast("info", $t("toast.download_preparing"));
- } catch (e: any) {
- const msg = typeof e === "string" ? e : e.message ?? $t("common.error");
- showToast("error", msg);
- }
- }
-
- let refreshing = $state(false);
-
- async function refreshCourses() {
- refreshing = true;
- loadingCourses = true;
- coursesError = "";
- try {
- courses = await pluginInvoke("courses", "medcof_refresh_courses");
- currentPage = 1;
- } catch (e: any) {
- coursesError = typeof e === "string" ? e : e.message ?? $t('hotmart.courses_error');
- } finally {
- loadingCourses = false;
- refreshing = false;
- }
- }
-</script>
-
-<a href="/courses" class="back-link">
- <svg viewBox="0 0 24 24" width="16" height="16" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
- <path d="M19 12H5" />
- <path d="M12 19l-7-7 7-7" />
- </svg>
- {$t("courses.back")}
-</a>
-
-{#if checking}
- <div class="page-center">
- <span class="spinner"></span>
- <span class="spinner-text">{$t('hotmart.checking_session')}</span>
- </div>
-{:else if loggedIn}
- <div class="page-logged">
- <div class="session-bar">
- <span class="session-info">
- {$t('hotmart.logged_as', { email: sessionEmail || "—" })}
- </span>
- <div class="session-actions">
- <button
- class="button"
- onclick={refreshCourses}
- disabled={refreshing}
- aria-label={$t('hotmart.refresh')}
- >
- <svg viewBox="0 0 24 24" width="14" height="14" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class:spinning={refreshing}>
- <path d="M21 2v6h-6" />
- <path d="M3 12a9 9 0 0115-6.7L21 8" />
- <path d="M3 22v-6h6" />
- <path d="M21 12a9 9 0 01-15 6.7L3 16" />
- </svg>
- </button>
- <button class="button" onclick={handleLogout}>{$t('hotmart.logout')}</button>
- </div>
- </div>
-
- {#if loadingCourses}
- <div class="spinner-section">
- <span class="spinner"></span>
- <span class="spinner-text">{$t('hotmart.loading_courses')}</span>
- </div>
- {:else if coursesError}
- <div class="error-section">
- <p class="error-msg">{coursesError}</p>
- <button class="button" onclick={loadCourses}>{$t('common.retry')}</button>
- </div>
- {:else if courses.length === 0}
- <p class="empty-text">{$t('hotmart.no_courses')}</p>
- {:else}
- <div class="courses-header">
- <h2>{$t('hotmart.courses_title')}</h2>
- <span class="subtext">{courses.length === 1 ? $t('hotmart.course_count_one', { count: courses.length }) : $t('hotmart.course_count', { count: courses.length })}</span>
- </div>
-
- <div class="courses-grid">
- {#each paginatedCourses as course (course.id)}
- <CourseCard
- name={course.name}
- price=""
- downloadStatus={getCourseDownloadStatus(course.id)}
- downloadPercent={getCourseDownloadPercent(course.id)}
- onDownload={() => downloadCourse(course)}
- />
- {/each}
- </div>
-
- {#if totalPages > 1}
- <div class="pagination">
- <span class="pagination-info">
- {$t('hotmart.page_of', { current: currentPage, total: totalPages })} &middot; {courses.length === 1 ? $t('hotmart.course_count_one', { count: courses.length }) : $t('hotmart.course_count', { count: courses.length })}
- </span>
- <div class="pagination-controls">
- <button
- class="button pagination-btn"
- disabled={currentPage <= 1}
- onclick={() => goToPage(currentPage - 1)}
- >
- &lt;
- </button>
-
- {#each pageNumbers() as page}
- {#if page === -1}
- <span class="pagination-ellipsis">&hellip;</span>
- {:else}
- <button
- class="button pagination-btn"
- class:active={page === currentPage}
- onclick={() => goToPage(page)}
- >
- {page}
- </button>
- {/if}
- {/each}
-
- <button
- class="button pagination-btn"
- disabled={currentPage >= totalPages}
- onclick={() => goToPage(currentPage + 1)}
- >
- &gt;
- </button>
- </div>
- </div>
- {/if}
- {/if}
- </div>
-{:else}
- <div class="page-center">
- <div class="login-card">
- <h2>Medcof</h2>
-
- <div class="form">
- <label class="field">
- <span class="field-label">Cookies JSON</span>
- <textarea
- class="input token-textarea"
- placeholder="Paste cookies JSON from browser extension or a raw token"
- bind:value={token}
- disabled={loading}
- rows="4"
- ></textarea>
- </label>
- <input type="file" accept=".json,.txt" class="hidden-file-input" bind:this={fileInput} onchange={onFileSelected} />
- <button class="button" onclick={() => fileInput?.click()} disabled={loading}>Import .json file</button>
-
- {#if error}
- <p class="error-msg">{error}</p>
- {/if}
-
- <button class="button" onclick={handleTokenLogin} disabled={loading || !token.trim()}>
- {#if loading}
- {$t('hotmart.authenticating')}
- {:else}
- {$t('hotmart.login')}
- {/if}
- </button>
- </div>
- </div>
- </div>
-{/if}
-
-<style>
- .back-link {
- display: inline-flex;
- align-items: center;
- gap: 6px;
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- margin-bottom: var(--padding);
- }
-
- @media (hover: hover) {
- .back-link:hover {
- color: var(--secondary);
- }
- }
-
- .page-center {
- display: flex;
- flex-direction: column;
- align-items: center;
- justify-content: center;
- min-height: calc(100vh - var(--padding) * 4 - 40px);
- gap: var(--padding);
- }
-
- .page-logged {
- display: flex;
- flex-direction: column;
- align-items: center;
- gap: calc(var(--padding) * 1.5);
- padding: calc(var(--padding) * 1.5);
- width: 100%;
- }
-
- .page-logged > :global(*) {
- width: 100%;
- max-width: 1200px;
- }
-
- .session-bar {
- display: flex;
- align-items: center;
- justify-content: space-between;
- }
-
- .session-info {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .session-actions {
- display: flex;
- gap: calc(var(--padding) / 2);
- }
-
- .session-bar :global(.button) {
- padding: calc(var(--padding) / 2) var(--padding);
- font-size: 12.5px;
- }
-
- .spinning {
- animation: spin 0.6s linear infinite;
- }
-
- .courses-header {
- display: flex;
- align-items: baseline;
- gap: var(--padding);
- }
-
- .courses-header h2 {
- margin-block: 0;
- }
-
- .subtext {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .courses-grid {
- display: grid;
- grid-template-columns: repeat(4, 1fr);
- gap: var(--padding);
- }
-
- @media (max-width: 1000px) {
- .courses-grid {
- grid-template-columns: repeat(3, 1fr);
- }
- }
-
- @media (max-width: 750px) {
- .courses-grid {
- grid-template-columns: repeat(2, 1fr);
- }
- }
-
- @media (max-width: 535px) {
- .courses-grid {
- grid-template-columns: 1fr;
- }
- }
-
- .pagination {
- display: flex;
- flex-direction: column;
- align-items: center;
- gap: var(--padding);
- padding-top: var(--padding);
- }
-
- .pagination-info {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .pagination-controls {
- display: flex;
- align-items: center;
- gap: calc(var(--padding) / 3);
- }
-
- .pagination-btn {
- min-width: 36px;
- height: 36px;
- padding: 0;
- display: flex;
- align-items: center;
- justify-content: center;
- font-size: 14.5px;
- }
-
- .pagination-ellipsis {
- min-width: 36px;
- text-align: center;
- color: var(--gray);
- font-size: 14.5px;
- }
-
- .login-card {
- width: 100%;
- max-width: 400px;
- background: var(--button-elevated);
- border-radius: var(--border-radius);
- padding: calc(var(--padding) * 2);
- display: flex;
- flex-direction: column;
- gap: calc(var(--padding) * 1.5);
- }
-
- .login-card h2 {
- margin-block: 0;
- }
-
- .hidden-file-input {
- display: none;
- }
-
- .token-textarea {
- resize: vertical;
- min-height: 80px;
- font-size: 11.5px;
- font-family: var(--font-mono);
- line-height: 1.5;
- }
-
- .form {
- display: flex;
- flex-direction: column;
- gap: var(--padding);
- }
-
- .field {
- display: flex;
- flex-direction: column;
- gap: calc(var(--padding) / 2);
- }
-
- .field-label {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .input {
- width: 100%;
- padding: var(--padding);
- font-size: 14.5px;
- background: var(--button);
- border-radius: var(--border-radius);
- color: var(--secondary);
- border: 1px solid var(--input-border);
- }
-
- .input::placeholder {
- color: var(--gray);
- }
-
- .input:focus-visible {
- border-color: var(--secondary);
- outline: none;
- }
-
- .input:disabled {
- opacity: 0.5;
- cursor: default;
- }
-
- .error-msg {
- color: var(--red);
- font-size: 12.5px;
- font-weight: 500;
- }
-
- .spinner-section {
- display: flex;
- flex-direction: column;
- align-items: center;
- gap: var(--padding);
- padding: calc(var(--padding) * 4) 0;
- }
-
- .spinner {
- width: 24px;
- height: 24px;
- border: 2px solid var(--input-border);
- border-top-color: var(--blue);
- border-radius: 50%;
- animation: spin 0.6s linear infinite;
- }
-
- @keyframes spin {
- to {
- transform: rotate(360deg);
- }
- }
-
- .spinner-text {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .error-section {
- display: flex;
- flex-direction: column;
- align-items: center;
- gap: var(--padding);
- padding: calc(var(--padding) * 2) 0;
- }
-
- .empty-text {
- color: var(--gray);
- font-size: 14.5px;
- text-align: center;
- padding: calc(var(--padding) * 4) 0;
- }
-</style>
\ No newline at end of file
diff --git a/src/routes/courses/medway/+page.svelte b/src/routes/courses/medway/+page.svelte
deleted file mode 100644
index 44b56386..00000000
--- a/src/routes/courses/medway/+page.svelte
+++ /dev/null
@@ -1,605 +0,0 @@
-<script lang="ts">
- import { pluginInvoke } from "$lib/plugin-invoke";
- import { open } from "@tauri-apps/plugin-dialog";
- import CourseCard from "$components/hotmart/CourseCard.svelte";
- import { showToast } from "$lib/stores/toast-store.svelte";
- import { getDownloads } from "$lib/stores/download-store.svelte";
- import { getSettings } from "$lib/stores/settings-store.svelte";
- import { t } from "$lib/i18n";
-
- let downloads = $derived(getDownloads());
-
- type MedwayCourse = {
- id: number;
- name: string;
- };
-
- let token = $state("");
- let loading = $state(false);
- let error = $state("");
-
- let fileInput: HTMLInputElement = $state() as HTMLInputElement;
-
- function onFileSelected(e: Event) {
- const input = e.target as HTMLInputElement;
- const file = input.files?.[0];
- if (!file) return;
- const reader = new FileReader();
- reader.onload = () => { token = reader.result as string; };
- reader.readAsText(file);
- input.value = "";
- }
-
- let checking = $state(true);
- let loggedIn = $state(false);
- let sessionEmail = $state("");
-
- let courses: MedwayCourse[] = $state([]);
- let loadingCourses = $state(false);
- let coursesError = $state("");
-
- const ITEMS_PER_PAGE = 12;
- let currentPage = $state(1);
-
- let totalPages = $derived(Math.max(1, Math.ceil(courses.length / ITEMS_PER_PAGE)));
- let paginatedCourses = $derived(
- courses.slice((currentPage - 1) * ITEMS_PER_PAGE, currentPage * ITEMS_PER_PAGE)
- );
-
- let pageNumbers = $derived((): number[] => {
- const pages: number[] = [];
- if (totalPages <= 7) {
- for (let i = 1; i <= totalPages; i++) pages.push(i);
- } else {
- pages.push(1);
- if (currentPage > 3) pages.push(-1);
- const start = Math.max(2, currentPage - 1);
- const end = Math.min(totalPages - 1, currentPage + 1);
- for (let i = start; i <= end; i++) pages.push(i);
- if (currentPage < totalPages - 2) pages.push(-1);
- pages.push(totalPages);
- }
- return pages;
- });
-
- function goToPage(page: number) {
- if (page >= 1 && page <= totalPages) {
- currentPage = page;
- }
- }
-
- $effect(() => {
- checkSession();
- });
-
- async function checkSession() {
- try {
- const result = await pluginInvoke<string>("courses", "medway_check_session");
- sessionEmail = result;
- loggedIn = true;
- loadCourses();
- } catch {
- loggedIn = false;
- } finally {
- checking = false;
- }
- }
-
- async function handleTokenLogin() {
- if (!token.trim()) return;
- error = "";
- loading = true;
- try {
- const result = await pluginInvoke<string>("courses", "medway_login_token", { token: token.trim() });
- sessionEmail = result || "Token";
- loggedIn = true;
- loadCourses();
- } catch (e: any) {
- error = typeof e === "string" ? e : e.message ?? $t('hotmart.unknown_error');
- } finally {
- loading = false;
- }
- }
-
- async function handleLogout() {
- try {
- await pluginInvoke("courses", "medway_logout");
- } catch {
- }
- loggedIn = false;
- sessionEmail = "";
- courses = [];
- coursesError = "";
- currentPage = 1;
- }
-
- async function loadCourses() {
- loadingCourses = true;
- coursesError = "";
- try {
- courses = await pluginInvoke("courses", "medway_list_courses");
- currentPage = 1;
- } catch (e: any) {
- coursesError = typeof e === "string" ? e : e.message ?? $t('hotmart.courses_error');
- } finally {
- loadingCourses = false;
- }
- }
-
- function getCourseDownloadStatus(courseId: number): "idle" | "downloading" | "complete" | "error" {
- const item = downloads.get(courseId);
- if (!item) return "idle";
- const s = item.status;
- if (s === "queued" || s === "paused" || s === "seeding") return "downloading";
- return s;
- }
-
- function getCourseDownloadPercent(courseId: number): number {
- return downloads.get(courseId)?.percent ?? 0;
- }
-
- async function downloadCourse(course: MedwayCourse) {
- const status = getCourseDownloadStatus(course.id);
- if (status === "downloading") {
- showToast("info", $t("toast.download_already_active"));
- return;
- }
- if (status === "complete") return;
-
- const appSettings = getSettings();
- let outputDir: string | null = null;
-
- if (appSettings?.download.always_ask_path) {
- outputDir = await open({ directory: true, title: $t("hotmart.choose_folder") }) as string | null;
- if (!outputDir) return;
- } else {
- outputDir = appSettings?.download.default_output_dir ?? null;
- if (!outputDir) {
- outputDir = await open({ directory: true, title: $t("hotmart.choose_folder") }) as string | null;
- if (!outputDir) return;
- }
- }
-
- try {
- await pluginInvoke("courses", "start_medway_course_download", {
- courseJson: JSON.stringify(course),
- outputDir,
- });
- showToast("info", $t("toast.download_preparing"));
- } catch (e: any) {
- const msg = typeof e === "string" ? e : e.message ?? $t("common.error");
- showToast("error", msg);
- }
- }
-
- let refreshing = $state(false);
-
- async function refreshCourses() {
- refreshing = true;
- loadingCourses = true;
- coursesError = "";
- try {
- courses = await pluginInvoke("courses", "medway_refresh_courses");
- currentPage = 1;
- } catch (e: any) {
- coursesError = typeof e === "string" ? e : e.message ?? $t('hotmart.courses_error');
- } finally {
- loadingCourses = false;
- refreshing = false;
- }
- }
-</script>
-
-<a href="/courses" class="back-link">
- <svg viewBox="0 0 24 24" width="16" height="16" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
- <path d="M19 12H5" />
- <path d="M12 19l-7-7 7-7" />
- </svg>
- {$t("courses.back")}
-</a>
-
-{#if checking}
- <div class="page-center">
- <span class="spinner"></span>
- <span class="spinner-text">{$t('hotmart.checking_session')}</span>
- </div>
-{:else if loggedIn}
- <div class="page-logged">
- <div class="session-bar">
- <span class="session-info">
- {$t('hotmart.logged_as', { email: sessionEmail || "\u2014" })}
- </span>
- <div class="session-actions">
- <button
- class="button"
- onclick={refreshCourses}
- disabled={refreshing}
- aria-label={$t('hotmart.refresh')}
- >
- <svg viewBox="0 0 24 24" width="14" height="14" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class:spinning={refreshing}>
- <path d="M21 2v6h-6" />
- <path d="M3 12a9 9 0 0115-6.7L21 8" />
- <path d="M3 22v-6h6" />
- <path d="M21 12a9 9 0 01-15 6.7L3 16" />
- </svg>
- </button>
- <button class="button" onclick={handleLogout}>{$t('hotmart.logout')}</button>
- </div>
- </div>
-
- {#if loadingCourses}
- <div class="spinner-section">
- <span class="spinner"></span>
- <span class="spinner-text">{$t('hotmart.loading_courses')}</span>
- </div>
- {:else if coursesError}
- <div class="error-section">
- <p class="error-msg">{coursesError}</p>
- <button class="button" onclick={loadCourses}>{$t('common.retry')}</button>
- </div>
- {:else if courses.length === 0}
- <p class="empty-text">{$t('hotmart.no_courses')}</p>
- {:else}
- <div class="courses-header">
- <h2>{$t('hotmart.courses_title')}</h2>
- <span class="subtext">{courses.length === 1 ? $t('hotmart.course_count_one', { count: courses.length }) : $t('hotmart.course_count', { count: courses.length })}</span>
- </div>
-
- <div class="courses-grid">
- {#each paginatedCourses as course (course.id)}
- <CourseCard
- name={course.name}
- price={""}
- downloadStatus={getCourseDownloadStatus(course.id)}
- downloadPercent={getCourseDownloadPercent(course.id)}
- onDownload={() => downloadCourse(course)}
- />
- {/each}
- </div>
-
- {#if totalPages > 1}
- <div class="pagination">
- <span class="pagination-info">
- {$t('hotmart.page_of', { current: currentPage, total: totalPages })} &middot; {courses.length === 1 ? $t('hotmart.course_count_one', { count: courses.length }) : $t('hotmart.course_count', { count: courses.length })}
- </span>
- <div class="pagination-controls">
- <button
- class="button pagination-btn"
- disabled={currentPage <= 1}
- onclick={() => goToPage(currentPage - 1)}
- >
- &lt;
- </button>
-
- {#each pageNumbers() as page}
- {#if page === -1}
- <span class="pagination-ellipsis">&hellip;</span>
- {:else}
- <button
- class="button pagination-btn"
- class:active={page === currentPage}
- onclick={() => goToPage(page)}
- >
- {page}
- </button>
- {/if}
- {/each}
-
- <button
- class="button pagination-btn"
- disabled={currentPage >= totalPages}
- onclick={() => goToPage(currentPage + 1)}
- >
- &gt;
- </button>
- </div>
- </div>
- {/if}
- {/if}
- </div>
-{:else}
- <div class="page-center">
- <div class="login-card">
- <h2>Medway</h2>
-
- <div class="form">
- <label class="field">
- <span class="field-label">Cookies JSON</span>
- <textarea
- class="input token-textarea"
- placeholder="Paste cookies JSON from browser extension or a raw token"
- bind:value={token}
- disabled={loading}
- rows="5"
- ></textarea>
- </label>
-
- <input
- type="file"
- accept=".json,.txt"
- class="hidden-file-input"
- bind:this={fileInput}
- onchange={onFileSelected}
- />
- <button class="button" onclick={() => fileInput?.click()} disabled={loading}>
- Import .json file
- </button>
-
- {#if error}
- <p class="error-msg">{error}</p>
- {/if}
-
- <button class="button" onclick={handleTokenLogin} disabled={loading || !token.trim()}>
- {#if loading}
- {$t('hotmart.authenticating')}
- {:else}
- {$t('hotmart.login')}
- {/if}
- </button>
- </div>
- </div>
- </div>
-{/if}
-
-<style>
- .back-link {
- display: inline-flex;
- align-items: center;
- gap: 6px;
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- margin-bottom: var(--padding);
- }
-
- @media (hover: hover) {
- .back-link:hover {
- color: var(--secondary);
- }
- }
-
- .page-center {
- display: flex;
- flex-direction: column;
- align-items: center;
- justify-content: center;
- min-height: calc(100vh - var(--padding) * 4 - 40px);
- gap: var(--padding);
- }
-
- .page-logged {
- display: flex;
- flex-direction: column;
- align-items: center;
- gap: calc(var(--padding) * 1.5);
- padding: calc(var(--padding) * 1.5);
- width: 100%;
- }
-
- .page-logged > :global(*) {
- width: 100%;
- max-width: 1200px;
- }
-
- .session-bar {
- display: flex;
- align-items: center;
- justify-content: space-between;
- }
-
- .session-info {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .session-actions {
- display: flex;
- gap: calc(var(--padding) / 2);
- }
-
- .session-bar :global(.button) {
- padding: calc(var(--padding) / 2) var(--padding);
- font-size: 12.5px;
- }
-
- .spinning {
- animation: spin 0.6s linear infinite;
- }
-
- .courses-header {
- display: flex;
- align-items: baseline;
- gap: var(--padding);
- }
-
- .courses-header h2 {
- margin-block: 0;
- }
-
- .subtext {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .courses-grid {
- display: grid;
- grid-template-columns: repeat(4, 1fr);
- gap: var(--padding);
- }
-
- @media (max-width: 1000px) {
- .courses-grid {
- grid-template-columns: repeat(3, 1fr);
- }
- }
-
- @media (max-width: 750px) {
- .courses-grid {
- grid-template-columns: repeat(2, 1fr);
- }
- }
-
- @media (max-width: 535px) {
- .courses-grid {
- grid-template-columns: 1fr;
- }
- }
-
- .pagination {
- display: flex;
- flex-direction: column;
- align-items: center;
- gap: var(--padding);
- padding-top: var(--padding);
- }
-
- .pagination-info {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .pagination-controls {
- display: flex;
- align-items: center;
- gap: calc(var(--padding) / 3);
- }
-
- .pagination-btn {
- min-width: 36px;
- height: 36px;
- padding: 0;
- display: flex;
- align-items: center;
- justify-content: center;
- font-size: 14.5px;
- }
-
- .pagination-ellipsis {
- min-width: 36px;
- text-align: center;
- color: var(--gray);
- font-size: 14.5px;
- }
-
- .login-card {
- width: 100%;
- max-width: 400px;
- background: var(--button-elevated);
- border-radius: var(--border-radius);
- padding: calc(var(--padding) * 2);
- display: flex;
- flex-direction: column;
- gap: calc(var(--padding) * 1.5);
- }
-
- .login-card h2 {
- margin-block: 0;
- }
-
- .hidden-file-input {
- display: none;
- }
-
- .token-textarea {
- resize: vertical;
- min-height: 80px;
- font-size: 11.5px;
- font-family: var(--font-mono);
- line-height: 1.5;
- }
-
- .form {
- display: flex;
- flex-direction: column;
- gap: var(--padding);
- }
-
- .field {
- display: flex;
- flex-direction: column;
- gap: calc(var(--padding) / 2);
- }
-
- .field-label {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .input {
- width: 100%;
- padding: var(--padding);
- font-size: 14.5px;
- background: var(--button);
- border-radius: var(--border-radius);
- color: var(--secondary);
- border: 1px solid var(--input-border);
- }
-
- .input::placeholder {
- color: var(--gray);
- }
-
- .input:focus-visible {
- border-color: var(--secondary);
- outline: none;
- }
-
- .input:disabled {
- opacity: 0.5;
- cursor: default;
- }
-
- .error-msg {
- color: var(--red);
- font-size: 12.5px;
- font-weight: 500;
- }
-
- .spinner-section {
- display: flex;
- flex-direction: column;
- align-items: center;
- gap: var(--padding);
- padding: calc(var(--padding) * 4) 0;
- }
-
- .spinner {
- width: 24px;
- height: 24px;
- border: 2px solid var(--input-border);
- border-top-color: var(--blue);
- border-radius: 50%;
- animation: spin 0.6s linear infinite;
- }
-
- @keyframes spin {
- to {
- transform: rotate(360deg);
- }
- }
-
- .spinner-text {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .error-section {
- display: flex;
- flex-direction: column;
- align-items: center;
- gap: var(--padding);
- padding: calc(var(--padding) * 2) 0;
- }
-
- .empty-text {
- color: var(--gray);
- font-size: 14.5px;
- text-align: center;
- padding: calc(var(--padding) * 4) 0;
- }
-</style>
diff --git a/src/routes/courses/memberkit/+page.svelte b/src/routes/courses/memberkit/+page.svelte
deleted file mode 100644
index 70117a2b..00000000
--- a/src/routes/courses/memberkit/+page.svelte
+++ /dev/null
@@ -1,723 +0,0 @@
-<script lang="ts">
- import { pluginInvoke } from "$lib/plugin-invoke";
- import { open } from "@tauri-apps/plugin-dialog";
- import CourseCard from "$components/hotmart/CourseCard.svelte";
- import { showToast } from "$lib/stores/toast-store.svelte";
- import { getDownloads } from "$lib/stores/download-store.svelte";
- import { getSettings } from "$lib/stores/settings-store.svelte";
- import { t } from "$lib/i18n";
-
- let downloads = $derived(getDownloads());
-
- type MemberkitCourse = {
- id: string;
- name: string;
- slug: string;
- };
-
- let email = $state("");
- let password = $state("");
- let cookie = $state("");
- let siteUrl = $state("");
- let loading = $state(false);
- let error = $state("");
-
- let checking = $state(true);
- let loggedIn = $state(false);
- let sessionEmail = $state("");
-
- let loginMode = $state<"credentials" | "cookie">("credentials");
-
- let fileInput: HTMLInputElement = $state() as HTMLInputElement;
-
- function onFileSelected(e: Event) {
- const input = e.target as HTMLInputElement;
- const file = input.files?.[0];
- if (!file) return;
- const reader = new FileReader();
- reader.onload = () => { cookie = reader.result as string; };
- reader.readAsText(file);
- input.value = "";
- }
-
- let courses: MemberkitCourse[] = $state([]);
- let loadingCourses = $state(false);
- let coursesError = $state("");
-
- const ITEMS_PER_PAGE = 12;
- let currentPage = $state(1);
-
- let totalPages = $derived(Math.max(1, Math.ceil(courses.length / ITEMS_PER_PAGE)));
- let paginatedCourses = $derived(
- courses.slice((currentPage - 1) * ITEMS_PER_PAGE, currentPage * ITEMS_PER_PAGE)
- );
-
- let pageNumbers = $derived((): number[] => {
- const pages: number[] = [];
- if (totalPages <= 7) {
- for (let i = 1; i <= totalPages; i++) pages.push(i);
- } else {
- pages.push(1);
- if (currentPage > 3) pages.push(-1);
- const start = Math.max(2, currentPage - 1);
- const end = Math.min(totalPages - 1, currentPage + 1);
- for (let i = start; i <= end; i++) pages.push(i);
- if (currentPage < totalPages - 2) pages.push(-1);
- pages.push(totalPages);
- }
- return pages;
- });
-
- function goToPage(page: number) {
- if (page >= 1 && page <= totalPages) {
- currentPage = page;
- }
- }
-
- $effect(() => {
- checkSession();
- });
-
- async function checkSession() {
- try {
- const result = await pluginInvoke<string>("courses", "memberkit_check_session");
- sessionEmail = result;
- loggedIn = true;
- loadCourses();
- } catch {
- loggedIn = false;
- } finally {
- checking = false;
- }
- }
-
- async function handleLogin() {
- error = "";
- loading = true;
- try {
- const result = await pluginInvoke<string>("courses", "memberkit_login", { email, password, siteUrl: siteUrl.trim() });
- sessionEmail = result || email;
- loggedIn = true;
- loadCourses();
- } catch (e: any) {
- error = typeof e === "string" ? e : e.message ?? $t('hotmart.unknown_error');
- } finally {
- loading = false;
- }
- }
-
- async function handleCookieLogin() {
- if (!cookie.trim()) return;
- error = "";
- loading = true;
- try {
- const result = await pluginInvoke<string>("courses", "memberkit_login_cookie", { cookie: cookie.trim(), siteUrl: siteUrl.trim() });
- sessionEmail = result || "Cookie";
- loggedIn = true;
- loadCourses();
- } catch (e: any) {
- error = typeof e === "string" ? e : e.message ?? $t('hotmart.unknown_error');
- } finally {
- loading = false;
- }
- }
-
- async function handleLogout() {
- try {
- await pluginInvoke("courses", "memberkit_logout");
- } catch {
- }
- loggedIn = false;
- sessionEmail = "";
- courses = [];
- coursesError = "";
- currentPage = 1;
- }
-
- async function loadCourses() {
- loadingCourses = true;
- coursesError = "";
- try {
- courses = await pluginInvoke("courses", "memberkit_list_courses");
- currentPage = 1;
- } catch (e: any) {
- coursesError = typeof e === "string" ? e : e.message ?? $t('hotmart.courses_error');
- } finally {
- loadingCourses = false;
- }
- }
-
- function getCourseDownloadStatus(courseId: string): "idle" | "downloading" | "complete" | "error" {
- const numId = Number(courseId) || 0;
- const item = downloads.get(numId);
- if (!item) return "idle";
- const s = item.status;
- if (s === "queued" || s === "paused" || s === "seeding") return "downloading";
- return s;
- }
-
- function getCourseDownloadPercent(courseId: string): number {
- const numId = Number(courseId) || 0;
- return downloads.get(numId)?.percent ?? 0;
- }
-
- async function downloadCourse(course: MemberkitCourse) {
- const status = getCourseDownloadStatus(course.id);
- if (status === "downloading") {
- showToast("info", $t("toast.download_already_active"));
- return;
- }
- if (status === "complete") return;
-
- const appSettings = getSettings();
- let outputDir: string | null = null;
-
- if (appSettings?.download.always_ask_path) {
- outputDir = await open({ directory: true, title: $t("hotmart.choose_folder") }) as string | null;
- if (!outputDir) return;
- } else {
- outputDir = appSettings?.download.default_output_dir ?? null;
- if (!outputDir) {
- outputDir = await open({ directory: true, title: $t("hotmart.choose_folder") }) as string | null;
- if (!outputDir) return;
- }
- }
-
- try {
- await pluginInvoke("courses", "start_memberkit_download", {
- courseJson: JSON.stringify(course),
- outputDir,
- });
- showToast("info", $t("toast.download_preparing"));
- } catch (e: any) {
- const msg = typeof e === "string" ? e : e.message ?? $t("common.error");
- showToast("error", msg);
- }
- }
-
- let refreshing = $state(false);
-
- async function refreshCourses() {
- refreshing = true;
- loadingCourses = true;
- coursesError = "";
- try {
- courses = await pluginInvoke("courses", "memberkit_refresh_courses");
- currentPage = 1;
- } catch (e: any) {
- coursesError = typeof e === "string" ? e : e.message ?? $t('hotmart.courses_error');
- } finally {
- loadingCourses = false;
- refreshing = false;
- }
- }
-</script>
-
-<a href="/courses" class="back-link">
- <svg viewBox="0 0 24 24" width="16" height="16" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
- <path d="M19 12H5" />
- <path d="M12 19l-7-7 7-7" />
- </svg>
- {$t("courses.back")}
-</a>
-
-{#if checking}
- <div class="page-center">
- <span class="spinner"></span>
- <span class="spinner-text">{$t('hotmart.checking_session')}</span>
- </div>
-{:else if loggedIn}
- <div class="page-logged">
- <div class="session-bar">
- <span class="session-info">
- {$t('hotmart.logged_as', { email: sessionEmail || "—" })}
- </span>
- <div class="session-actions">
- <button
- class="button"
- onclick={refreshCourses}
- disabled={refreshing}
- aria-label={$t('hotmart.refresh')}
- >
- <svg viewBox="0 0 24 24" width="14" height="14" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class:spinning={refreshing}>
- <path d="M21 2v6h-6" />
- <path d="M3 12a9 9 0 0115-6.7L21 8" />
- <path d="M3 22v-6h6" />
- <path d="M21 12a9 9 0 01-15 6.7L3 16" />
- </svg>
- </button>
- <button class="button" onclick={handleLogout}>{$t('hotmart.logout')}</button>
- </div>
- </div>
-
- {#if loadingCourses}
- <div class="spinner-section">
- <span class="spinner"></span>
- <span class="spinner-text">{$t('hotmart.loading_courses')}</span>
- </div>
- {:else if coursesError}
- <div class="error-section">
- <p class="error-msg">{coursesError}</p>
- <button class="button" onclick={loadCourses}>{$t('common.retry')}</button>
- </div>
- {:else if courses.length === 0}
- <p class="empty-text">{$t('hotmart.no_courses')}</p>
- {:else}
- <div class="courses-header">
- <h2>{$t('hotmart.courses_title')}</h2>
- <span class="subtext">{courses.length === 1 ? $t('hotmart.course_count_one', { count: courses.length }) : $t('hotmart.course_count', { count: courses.length })}</span>
- </div>
-
- <div class="courses-grid">
- {#each paginatedCourses as course (course.id)}
- <CourseCard
- name={course.name}
- price=""
- downloadStatus={getCourseDownloadStatus(course.id)}
- downloadPercent={getCourseDownloadPercent(course.id)}
- onDownload={() => downloadCourse(course)}
- />
- {/each}
- </div>
-
- {#if totalPages > 1}
- <div class="pagination">
- <span class="pagination-info">
- {$t('hotmart.page_of', { current: currentPage, total: totalPages })} &middot; {courses.length === 1 ? $t('hotmart.course_count_one', { count: courses.length }) : $t('hotmart.course_count', { count: courses.length })}
- </span>
- <div class="pagination-controls">
- <button
- class="button pagination-btn"
- disabled={currentPage <= 1}
- onclick={() => goToPage(currentPage - 1)}
- >
- &lt;
- </button>
-
- {#each pageNumbers() as page}
- {#if page === -1}
- <span class="pagination-ellipsis">&hellip;</span>
- {:else}
- <button
- class="button pagination-btn"
- class:active={page === currentPage}
- onclick={() => goToPage(page)}
- >
- {page}
- </button>
- {/if}
- {/each}
-
- <button
- class="button pagination-btn"
- disabled={currentPage >= totalPages}
- onclick={() => goToPage(currentPage + 1)}
- >
- &gt;
- </button>
- </div>
- </div>
- {/if}
- {/if}
- </div>
-{:else}
- <div class="page-center">
- <div class="login-card">
- <h2>MemberKit</h2>
-
- <div class="login-tabs">
- <button
- class="button login-tab"
- class:active={loginMode === "credentials"}
- onclick={() => { loginMode = "credentials"; error = ""; }}
- >
- Email & Password
- </button>
- <button
- class="button login-tab"
- class:active={loginMode === "cookie"}
- onclick={() => { loginMode = "cookie"; error = ""; }}
- >
- Cookie
- </button>
- </div>
-
- {#if loginMode === "credentials"}
- <form class="form" onsubmit={(e) => { e.preventDefault(); handleLogin(); }}>
- <label class="field">
- <span class="field-label">Platform URL</span>
- <input
- type="url"
- placeholder="https://example.memberkit.com.br"
- bind:value={siteUrl}
- class="input"
- disabled={loading}
- required
- />
- </label>
- <label class="field">
- <span class="field-label">{$t('hotmart.email_label')}</span>
- <input
- type="email"
- placeholder={$t('hotmart.email_placeholder')}
- bind:value={email}
- class="input"
- disabled={loading}
- required
- />
- </label>
- <label class="field">
- <span class="field-label">{$t('hotmart.password_label')}</span>
- <input
- type="password"
- placeholder={$t('hotmart.password_placeholder')}
- bind:value={password}
- class="input"
- disabled={loading}
- required
- />
- </label>
-
- {#if error}
- <p class="error-msg">{error}</p>
- {/if}
-
- <button type="submit" class="button" disabled={loading}>
- {#if loading}
- {$t('hotmart.authenticating')}
- {:else}
- {$t('hotmart.login')}
- {/if}
- </button>
- </form>
- {:else}
- <div class="form">
- <label class="field">
- <span class="field-label">Platform URL</span>
- <input
- type="url"
- placeholder="https://example.memberkit.com.br"
- bind:value={siteUrl}
- class="input"
- disabled={loading}
- />
- </label>
- <label class="field">
- <span class="field-label">Cookies JSON</span>
- <textarea
- class="input token-textarea"
- placeholder="Paste cookies JSON from browser extension or a raw token"
- bind:value={cookie}
- disabled={loading}
- rows="5"
- ></textarea>
- </label>
-
- <input
- type="file"
- accept=".json,.txt"
- class="hidden-file-input"
- bind:this={fileInput}
- onchange={onFileSelected}
- />
- <button class="button" onclick={() => fileInput?.click()} disabled={loading}>
- Import .json file
- </button>
-
- {#if error}
- <p class="error-msg">{error}</p>
- {/if}
-
- <button class="button" onclick={handleCookieLogin} disabled={loading || !cookie.trim()}>
- {#if loading}
- {$t('hotmart.authenticating')}
- {:else}
- {$t('hotmart.login')}
- {/if}
- </button>
- </div>
- {/if}
- </div>
- </div>
-{/if}
-
-<style>
- .back-link {
- display: inline-flex;
- align-items: center;
- gap: 6px;
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- margin-bottom: var(--padding);
- }
-
- @media (hover: hover) {
- .back-link:hover {
- color: var(--secondary);
- }
- }
-
- .page-center {
- display: flex;
- flex-direction: column;
- align-items: center;
- justify-content: center;
- min-height: calc(100vh - var(--padding) * 4 - 40px);
- gap: var(--padding);
- }
-
- .page-logged {
- display: flex;
- flex-direction: column;
- align-items: center;
- gap: calc(var(--padding) * 1.5);
- padding: calc(var(--padding) * 1.5);
- width: 100%;
- }
-
- .page-logged > :global(*) {
- width: 100%;
- max-width: 1200px;
- }
-
- .session-bar {
- display: flex;
- align-items: center;
- justify-content: space-between;
- }
-
- .session-info {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .session-actions {
- display: flex;
- gap: calc(var(--padding) / 2);
- }
-
- .session-bar :global(.button) {
- padding: calc(var(--padding) / 2) var(--padding);
- font-size: 12.5px;
- }
-
- .spinning {
- animation: spin 0.6s linear infinite;
- }
-
- .courses-header {
- display: flex;
- align-items: baseline;
- gap: var(--padding);
- }
-
- .courses-header h2 {
- margin-block: 0;
- }
-
- .subtext {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .courses-grid {
- display: grid;
- grid-template-columns: repeat(4, 1fr);
- gap: var(--padding);
- }
-
- @media (max-width: 1000px) {
- .courses-grid {
- grid-template-columns: repeat(3, 1fr);
- }
- }
-
- @media (max-width: 750px) {
- .courses-grid {
- grid-template-columns: repeat(2, 1fr);
- }
- }
-
- @media (max-width: 535px) {
- .courses-grid {
- grid-template-columns: 1fr;
- }
- }
-
- .pagination {
- display: flex;
- flex-direction: column;
- align-items: center;
- gap: var(--padding);
- padding-top: var(--padding);
- }
-
- .pagination-info {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .pagination-controls {
- display: flex;
- align-items: center;
- gap: calc(var(--padding) / 3);
- }
-
- .pagination-btn {
- min-width: 36px;
- height: 36px;
- padding: 0;
- display: flex;
- align-items: center;
- justify-content: center;
- font-size: 14.5px;
- }
-
- .pagination-ellipsis {
- min-width: 36px;
- text-align: center;
- color: var(--gray);
- font-size: 14.5px;
- }
-
- .login-card {
- width: 100%;
- max-width: 400px;
- background: var(--button-elevated);
- border-radius: var(--border-radius);
- padding: calc(var(--padding) * 2);
- display: flex;
- flex-direction: column;
- gap: calc(var(--padding) * 1.5);
- }
-
- .login-card h2 {
- margin-block: 0;
- }
-
- .login-tabs {
- display: flex;
- gap: 0;
- }
-
- .login-tab {
- flex: 1;
- border-radius: 0;
- font-size: 12.5px;
- padding: calc(var(--padding) * 0.75) var(--padding);
- }
-
- .login-tab:first-child {
- border-radius: var(--border-radius) 0 0 var(--border-radius);
- }
-
- .login-tab:last-child {
- border-radius: 0 var(--border-radius) var(--border-radius) 0;
- }
-
- .hidden-file-input { display: none; }
-
- .token-textarea {
- resize: vertical;
- min-height: 80px;
- font-size: 11.5px;
- font-family: var(--font-mono);
- line-height: 1.5;
- }
-
- .form {
- display: flex;
- flex-direction: column;
- gap: var(--padding);
- }
-
- .field {
- display: flex;
- flex-direction: column;
- gap: calc(var(--padding) / 2);
- }
-
- .field-label {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .input {
- width: 100%;
- padding: var(--padding);
- font-size: 14.5px;
- background: var(--button);
- border-radius: var(--border-radius);
- color: var(--secondary);
- border: 1px solid var(--input-border);
- }
-
- .input::placeholder {
- color: var(--gray);
- }
-
- .input:focus-visible {
- border-color: var(--secondary);
- outline: none;
- }
-
- .input:disabled {
- opacity: 0.5;
- cursor: default;
- }
-
- .error-msg {
- color: var(--red);
- font-size: 12.5px;
- font-weight: 500;
- }
-
- .spinner-section {
- display: flex;
- flex-direction: column;
- align-items: center;
- gap: var(--padding);
- padding: calc(var(--padding) * 4) 0;
- }
-
- .spinner {
- width: 24px;
- height: 24px;
- border: 2px solid var(--input-border);
- border-top-color: var(--blue);
- border-radius: 50%;
- animation: spin 0.6s linear infinite;
- }
-
- @keyframes spin {
- to {
- transform: rotate(360deg);
- }
- }
-
- .spinner-text {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .error-section {
- display: flex;
- flex-direction: column;
- align-items: center;
- gap: var(--padding);
- padding: calc(var(--padding) * 2) 0;
- }
-
- .empty-text {
- color: var(--gray);
- font-size: 14.5px;
- text-align: center;
- padding: calc(var(--padding) * 4) 0;
- }
-</style>
diff --git a/src/routes/courses/platform-icons.ts b/src/routes/courses/platform-icons.ts
deleted file mode 100644
index 40c018f7..00000000
--- a/src/routes/courses/platform-icons.ts
+++ /dev/null
@@ -1,37 +0,0 @@
-export const PLATFORM_ICONS: Record<string, string> = {
- hotmart: '<path d="M7 4v16" /><path d="M17 4v16" /><path d="M7 12h10" />',
- udemy: '<path d="M7 4l5-2 5 2" /><path d="M7 10v6a5 5 0 0 0 10 0v-6" />',
- kiwify: '<path d="M8 4v16" /><path d="M8 12l7-8" /><path d="M8 12l7 8" />',
- gumroad: '<circle cx="12" cy="12" r="9" /><path d="M12 8a4 4 0 1 0 0 8h0v-4" />',
- teachable: '<path d="M6 6h12" /><path d="M12 6v14" />',
- kajabi: '<path d="M8 4v16" /><path d="M8 12l6-8" /><path d="M8 12c2 2 4 5 7 7" />',
- skool: '<path d="M17 7a5 3 0 0 0-10 0c0 2 2 3 5 5s5 1 5 3a5 3 0 0 1-10 0" />',
- pluralsight: '<path d="M8 5v14l11-7z" />',
- greatcourses: '<path d="M4 5l4 14 4-10 4 10 4-14" />',
- masterclass: '<path d="M4 20V6l4 8 4-8 4 8 4-8v14" />',
- thinkific: '<path d="M5 5h14" /><path d="M12 5v15" />',
- curseduca: '<path d="M18 8a8 8 0 1 0-1 9" />',
- cademi: '<path d="M17 7a7 7 0 1 0 0 10" />',
- cakto: '<path d="M12 4v16" /><path d="M12 8h-3v4h3" /><path d="M12 11h3v4h-3" />',
- kirvano: '<path d="M8 4v16" /><path d="M16 4l-8 8 8 8" />',
- memberkit: '<path d="M12 3a4 4 0 1 0 0 8" /><path d="M12 11v9" /><path d="M10 16h4" />',
- rocketseat: '<path d="M12 2l-4 6h8z" /><path d="M12 8v12" /><path d="M9 18l3 4 3-4" />',
- grancursos: '<path d="M18 9a8 8 0 1 0-6 11" /><path d="M12 14h6" />',
- fluencyacademy: '<path d="M4 12a8 8 0 1 1 5 7l-3 3" /><path d="M10 10h4" /><path d="M10 14h2" />',
- datascienceacademy: '<path d="M4 12h4l2-6 4 12 2-6h4" />',
- medcel: '<path d="M12 4v16" /><path d="M4 12h16" />',
- medcof: '<path d="M12 3v18" /><path d="M8 7c0-2 8-2 8 0" /><path d="M8 11c0-2 8-2 8 0" />',
- medway: '<path d="M4 20l4-14 4 8 4-8 4 14" />',
- afyainternato: '<path d="M4 20l8-16 8 16" /><path d="M8 13h8" />',
- alpaclass: '<path d="M4 14l8-4 8 4" /><path d="M4 14v6l8 4 8-4v-6" />',
- areademembros: '<path d="M4 4h16v16H4z" /><path d="M12 9a2 2 0 1 0 0 4" /><path d="M9 15h6" />',
- astronmembers: '<path d="M12 2l3 7h7l-5.5 4.5 2 7L12 16l-6.5 4.5 2-7L2 9h7z" />',
- eduzznutror: '<path d="M17 5H8v14h9" /><path d="M8 12h7" />',
- entregadigital: '<path d="M12 3v12" /><path d="M8 11l4 4 4-4" /><path d="M5 17v2h14v-2" />',
- greennclub: '<path d="M12 20V10" /><path d="M12 10c-4-4-8 0-8 4" /><path d="M12 10c4-4 8 0 8 4" />',
- themembers: '<path d="M4 4h16v12H4z" /><path d="M10 8v4l3-2z" />',
- voompplay: '<path d="M5 5l7 7-7 7" /><path d="M13 5l7 7-7 7" />',
- estrategia: '<path d="M17 5H8v14h9" /><path d="M8 12h6" /><path d="M8 5h9" />',
-};
-
-export const DEFAULT_ICON = '<path d="M4 19.5A2.5 2.5 0 016.5 17H20" /><path d="M6.5 2H20v20H6.5A2.5 2.5 0 014 19.5v-15A2.5 2.5 0 016.5 2z" />';
diff --git a/src/routes/courses/pluralsight/+page.svelte b/src/routes/courses/pluralsight/+page.svelte
deleted file mode 100644
index 90c33ecf..00000000
--- a/src/routes/courses/pluralsight/+page.svelte
+++ /dev/null
@@ -1,599 +0,0 @@
-<script lang="ts">
- import { pluginInvoke } from "$lib/plugin-invoke";
- import { open } from "@tauri-apps/plugin-dialog";
- import CourseCard from "$components/hotmart/CourseCard.svelte";
- import { showToast } from "$lib/stores/toast-store.svelte";
- import { getDownloads } from "$lib/stores/download-store.svelte";
- import { getSettings } from "$lib/stores/settings-store.svelte";
- import { t } from "$lib/i18n";
-
- let downloads = $derived(getDownloads());
-
- type PluralsightCourse = {
- id: string;
- name: string;
- };
-
- let cookies = $state("");
- let fileInput: HTMLInputElement = $state() as HTMLInputElement;
- function onFileSelected(e: Event) {
- const input = e.target as HTMLInputElement;
- const file = input.files?.[0];
- if (!file) return;
- const reader = new FileReader();
- reader.onload = () => { cookies = reader.result as string; };
- reader.readAsText(file);
- input.value = "";
- }
- let loading = $state(false);
- let error = $state("");
-
- let checking = $state(true);
- let loggedIn = $state(false);
-
- let courses: PluralsightCourse[] = $state([]);
- let loadingCourses = $state(false);
- let coursesError = $state("");
-
- const ITEMS_PER_PAGE = 12;
- let currentPage = $state(1);
-
- let totalPages = $derived(Math.max(1, Math.ceil(courses.length / ITEMS_PER_PAGE)));
- let paginatedCourses = $derived(
- courses.slice((currentPage - 1) * ITEMS_PER_PAGE, currentPage * ITEMS_PER_PAGE)
- );
-
- let pageNumbers = $derived((): number[] => {
- const pages: number[] = [];
- if (totalPages <= 7) {
- for (let i = 1; i <= totalPages; i++) pages.push(i);
- } else {
- pages.push(1);
- if (currentPage > 3) pages.push(-1);
- const start = Math.max(2, currentPage - 1);
- const end = Math.min(totalPages - 1, currentPage + 1);
- for (let i = start; i <= end; i++) pages.push(i);
- if (currentPage < totalPages - 2) pages.push(-1);
- pages.push(totalPages);
- }
- return pages;
- });
-
- function goToPage(page: number) {
- if (page >= 1 && page <= totalPages) {
- currentPage = page;
- }
- }
-
- $effect(() => {
- checkSession();
- });
-
- async function checkSession() {
- try {
- await pluginInvoke<string>("courses", "pluralsight_check_session");
- loggedIn = true;
- loadCourses();
- } catch {
- loggedIn = false;
- } finally {
- checking = false;
- }
- }
-
- async function handleCookieLogin() {
- if (!cookies.trim()) return;
- error = "";
- loading = true;
- try {
- await pluginInvoke<string>("courses", "pluralsight_login_cookies", { cookies: cookies.trim() });
- loggedIn = true;
- loadCourses();
- } catch (e: any) {
- error = typeof e === "string" ? e : e.message ?? $t('hotmart.unknown_error');
- } finally {
- loading = false;
- }
- }
-
- async function handleLogout() {
- try {
- await pluginInvoke("courses", "pluralsight_logout");
- } catch {
- }
- loggedIn = false;
- courses = [];
- coursesError = "";
- currentPage = 1;
- }
-
- async function loadCourses() {
- loadingCourses = true;
- coursesError = "";
- try {
- courses = await pluginInvoke("courses", "pluralsight_list_courses");
- currentPage = 1;
- } catch (e: any) {
- coursesError = typeof e === "string" ? e : e.message ?? $t('hotmart.courses_error');
- } finally {
- loadingCourses = false;
- }
- }
-
- function getCourseDownloadStatus(courseId: string): "idle" | "downloading" | "complete" | "error" {
- const hash = hashString(courseId);
- const item = downloads.get(hash);
- if (!item) return "idle";
- const s = item.status;
- if (s === "queued" || s === "paused" || s === "seeding") return "downloading";
- return s;
- }
-
- function getCourseDownloadPercent(courseId: string): number {
- return downloads.get(hashString(courseId))?.percent ?? 0;
- }
-
- function hashString(str: string): number {
- let hash = 0;
- for (let i = 0; i < str.length; i++) {
- const char = str.charCodeAt(i);
- hash = ((hash << 5) - hash) + char;
- hash |= 0;
- }
- return Math.abs(hash);
- }
-
- async function downloadCourse(course: PluralsightCourse) {
- const status = getCourseDownloadStatus(course.id);
- if (status === "downloading") {
- showToast("info", $t("toast.download_already_active"));
- return;
- }
- if (status === "complete") return;
-
- const appSettings = getSettings();
- let outputDir: string | null = null;
-
- if (appSettings?.download.always_ask_path) {
- outputDir = await open({ directory: true, title: $t("hotmart.choose_folder") }) as string | null;
- if (!outputDir) return;
- } else {
- outputDir = appSettings?.download.default_output_dir ?? null;
- if (!outputDir) {
- outputDir = await open({ directory: true, title: $t("hotmart.choose_folder") }) as string | null;
- if (!outputDir) return;
- }
- }
-
- try {
- await pluginInvoke("courses", "start_pluralsight_course_download", {
- courseJson: JSON.stringify(course),
- outputDir,
- });
- showToast("info", $t("toast.download_preparing"));
- } catch (e: any) {
- const msg = typeof e === "string" ? e : e.message ?? $t("common.error");
- showToast("error", msg);
- }
- }
-
- let refreshing = $state(false);
-
- async function refreshCourses() {
- refreshing = true;
- loadingCourses = true;
- coursesError = "";
- try {
- courses = await pluginInvoke("courses", "pluralsight_refresh_courses");
- currentPage = 1;
- } catch (e: any) {
- coursesError = typeof e === "string" ? e : e.message ?? $t('hotmart.courses_error');
- } finally {
- loadingCourses = false;
- refreshing = false;
- }
- }
-</script>
-
-<a href="/courses" class="back-link">
- <svg viewBox="0 0 24 24" width="16" height="16" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
- <path d="M19 12H5" />
- <path d="M12 19l-7-7 7-7" />
- </svg>
- {$t("courses.back")}
-</a>
-
-{#if checking}
- <div class="page-center">
- <span class="spinner"></span>
- <span class="spinner-text">{$t('hotmart.checking_session')}</span>
- </div>
-{:else if loggedIn}
- <div class="page-logged">
- <div class="session-bar">
- <span class="session-info">Pluralsight</span>
- <div class="session-actions">
- <button
- class="button"
- onclick={refreshCourses}
- disabled={refreshing}
- aria-label={$t('hotmart.refresh')}
- >
- <svg viewBox="0 0 24 24" width="14" height="14" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class:spinning={refreshing}>
- <path d="M21 2v6h-6" />
- <path d="M3 12a9 9 0 0115-6.7L21 8" />
- <path d="M3 22v-6h6" />
- <path d="M21 12a9 9 0 01-15 6.7L3 16" />
- </svg>
- </button>
- <button class="button" onclick={handleLogout}>{$t('hotmart.logout')}</button>
- </div>
- </div>
-
- {#if loadingCourses}
- <div class="spinner-section">
- <span class="spinner"></span>
- <span class="spinner-text">{$t('hotmart.loading_courses')}</span>
- </div>
- {:else if coursesError}
- <div class="error-section">
- <p class="error-msg">{coursesError}</p>
- <button class="button" onclick={loadCourses}>{$t('common.retry')}</button>
- </div>
- {:else if courses.length === 0}
- <p class="empty-text">{$t('hotmart.no_courses')}</p>
- {:else}
- <div class="courses-header">
- <h2>{$t('hotmart.courses_title')}</h2>
- <span class="subtext">{courses.length === 1 ? $t('hotmart.course_count_one', { count: courses.length }) : $t('hotmart.course_count', { count: courses.length })}</span>
- </div>
-
- <div class="courses-grid">
- {#each paginatedCourses as course (course.id)}
- <CourseCard
- name={course.name}
- price=""
- downloadStatus={getCourseDownloadStatus(course.id)}
- downloadPercent={getCourseDownloadPercent(course.id)}
- onDownload={() => downloadCourse(course)}
- />
- {/each}
- </div>
-
- {#if totalPages > 1}
- <div class="pagination">
- <span class="pagination-info">
- {$t('hotmart.page_of', { current: currentPage, total: totalPages })} &middot; {courses.length === 1 ? $t('hotmart.course_count_one', { count: courses.length }) : $t('hotmart.course_count', { count: courses.length })}
- </span>
- <div class="pagination-controls">
- <button
- class="button pagination-btn"
- disabled={currentPage <= 1}
- onclick={() => goToPage(currentPage - 1)}
- >
- &lt;
- </button>
-
- {#each pageNumbers() as page}
- {#if page === -1}
- <span class="pagination-ellipsis">&hellip;</span>
- {:else}
- <button
- class="button pagination-btn"
- class:active={page === currentPage}
- onclick={() => goToPage(page)}
- >
- {page}
- </button>
- {/if}
- {/each}
-
- <button
- class="button pagination-btn"
- disabled={currentPage >= totalPages}
- onclick={() => goToPage(currentPage + 1)}
- >
- &gt;
- </button>
- </div>
- </div>
- {/if}
- {/if}
- </div>
-{:else}
- <div class="page-center">
- <div class="login-card">
- <h2>Pluralsight</h2>
-
- <div class="form">
- <label class="field">
- <span class="field-label">Cookies JSON</span>
- <textarea
- class="input token-textarea"
- placeholder="Paste cookies JSON from browser extension or a raw token"
- bind:value={cookies}
- disabled={loading}
- rows="4"
- ></textarea>
- </label>
- <input type="file" accept=".json,.txt" class="hidden-file-input" bind:this={fileInput} onchange={onFileSelected} />
- <button class="button" onclick={() => fileInput?.click()} disabled={loading}>Import .json file</button>
-
- {#if error}
- <p class="error-msg">{error}</p>
- {/if}
-
- <button class="button" onclick={handleCookieLogin} disabled={loading || !cookies.trim()}>
- {#if loading}
- {$t('hotmart.authenticating')}
- {:else}
- {$t('hotmart.login')}
- {/if}
- </button>
- </div>
- </div>
- </div>
-{/if}
-
-<style>
- .back-link {
- display: inline-flex;
- align-items: center;
- gap: 6px;
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- margin-bottom: var(--padding);
- }
-
- @media (hover: hover) {
- .back-link:hover {
- color: var(--secondary);
- }
- }
-
- .page-center {
- display: flex;
- flex-direction: column;
- align-items: center;
- justify-content: center;
- min-height: calc(100vh - var(--padding) * 4 - 40px);
- gap: var(--padding);
- }
-
- .page-logged {
- display: flex;
- flex-direction: column;
- align-items: center;
- gap: calc(var(--padding) * 1.5);
- padding: calc(var(--padding) * 1.5);
- width: 100%;
- }
-
- .page-logged > :global(*) {
- width: 100%;
- max-width: 1200px;
- }
-
- .session-bar {
- display: flex;
- align-items: center;
- justify-content: space-between;
- }
-
- .session-info {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .session-actions {
- display: flex;
- gap: calc(var(--padding) / 2);
- }
-
- .session-bar :global(.button) {
- padding: calc(var(--padding) / 2) var(--padding);
- font-size: 12.5px;
- }
-
- .spinning {
- animation: spin 0.6s linear infinite;
- }
-
- .courses-header {
- display: flex;
- align-items: baseline;
- gap: var(--padding);
- }
-
- .courses-header h2 {
- margin-block: 0;
- }
-
- .subtext {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .courses-grid {
- display: grid;
- grid-template-columns: repeat(4, 1fr);
- gap: var(--padding);
- }
-
- @media (max-width: 1000px) {
- .courses-grid {
- grid-template-columns: repeat(3, 1fr);
- }
- }
-
- @media (max-width: 750px) {
- .courses-grid {
- grid-template-columns: repeat(2, 1fr);
- }
- }
-
- @media (max-width: 535px) {
- .courses-grid {
- grid-template-columns: 1fr;
- }
- }
-
- .pagination {
- display: flex;
- flex-direction: column;
- align-items: center;
- gap: var(--padding);
- padding-top: var(--padding);
- }
-
- .pagination-info {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .pagination-controls {
- display: flex;
- align-items: center;
- gap: calc(var(--padding) / 3);
- }
-
- .pagination-btn {
- min-width: 36px;
- height: 36px;
- padding: 0;
- display: flex;
- align-items: center;
- justify-content: center;
- font-size: 14.5px;
- }
-
- .pagination-ellipsis {
- min-width: 36px;
- text-align: center;
- color: var(--gray);
- font-size: 14.5px;
- }
-
- .login-card {
- width: 100%;
- max-width: 400px;
- background: var(--button-elevated);
- border-radius: var(--border-radius);
- padding: calc(var(--padding) * 2);
- display: flex;
- flex-direction: column;
- gap: calc(var(--padding) * 1.5);
- }
-
- .login-card h2 {
- margin-block: 0;
- }
-
- .hidden-file-input {
- display: none;
- }
-
- .token-textarea {
- resize: vertical;
- min-height: 80px;
- font-size: 11.5px;
- font-family: var(--font-mono);
- line-height: 1.5;
- }
-
- .form {
- display: flex;
- flex-direction: column;
- gap: var(--padding);
- }
-
- .field {
- display: flex;
- flex-direction: column;
- gap: calc(var(--padding) / 2);
- }
-
- .field-label {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .input {
- width: 100%;
- padding: var(--padding);
- font-size: 14.5px;
- background: var(--button);
- border-radius: var(--border-radius);
- color: var(--secondary);
- border: 1px solid var(--input-border);
- }
-
- .input::placeholder {
- color: var(--gray);
- }
-
- .input:focus-visible {
- border-color: var(--secondary);
- outline: none;
- }
-
- .input:disabled {
- opacity: 0.5;
- cursor: default;
- }
-
- .error-msg {
- color: var(--red);
- font-size: 12.5px;
- font-weight: 500;
- }
-
- .spinner-section {
- display: flex;
- flex-direction: column;
- align-items: center;
- gap: var(--padding);
- padding: calc(var(--padding) * 4) 0;
- }
-
- .spinner {
- width: 24px;
- height: 24px;
- border: 2px solid var(--input-border);
- border-top-color: var(--blue);
- border-radius: 50%;
- animation: spin 0.6s linear infinite;
- }
-
- @keyframes spin {
- to {
- transform: rotate(360deg);
- }
- }
-
- .spinner-text {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .error-section {
- display: flex;
- flex-direction: column;
- align-items: center;
- gap: var(--padding);
- padding: calc(var(--padding) * 2) 0;
- }
-
- .empty-text {
- color: var(--gray);
- font-size: 14.5px;
- text-align: center;
- padding: calc(var(--padding) * 4) 0;
- }
-</style>
diff --git a/src/routes/courses/rocketseat/+page.svelte b/src/routes/courses/rocketseat/+page.svelte
deleted file mode 100644
index 7dae2369..00000000
--- a/src/routes/courses/rocketseat/+page.svelte
+++ /dev/null
@@ -1,643 +0,0 @@
-<script lang="ts">
- import { pluginInvoke } from "$lib/plugin-invoke";
- import { open } from "@tauri-apps/plugin-dialog";
- import CourseCard from "$components/hotmart/CourseCard.svelte";
- import { showToast } from "$lib/stores/toast-store.svelte";
- import { getDownloads } from "$lib/stores/download-store.svelte";
- import { getSettings } from "$lib/stores/settings-store.svelte";
- import { t } from "$lib/i18n";
-
- let downloads = $derived(getDownloads());
-
- type RocketseatCourse = {
- id: string;
- name: string;
- slug: string;
- description: string | null;
- };
-
- let token = $state("");
- let fileInput: HTMLInputElement = $state() as HTMLInputElement;
- function onFileSelected(e: Event) {
- const input = e.target as HTMLInputElement;
- const file = input.files?.[0];
- if (!file) return;
- const reader = new FileReader();
- reader.onload = () => { token = reader.result as string; };
- reader.readAsText(file);
- input.value = "";
- }
- let loading = $state(false);
- let error = $state("");
-
- let checking = $state(true);
- let loggedIn = $state(false);
-
- let courses: RocketseatCourse[] = $state([]);
- let loadingCourses = $state(false);
- let coursesError = $state("");
-
- const ITEMS_PER_PAGE = 12;
- let currentPage = $state(1);
-
- let totalPages = $derived(Math.max(1, Math.ceil(courses.length / ITEMS_PER_PAGE)));
- let paginatedCourses = $derived(
- courses.slice((currentPage - 1) * ITEMS_PER_PAGE, currentPage * ITEMS_PER_PAGE)
- );
-
- let pageNumbers = $derived((): number[] => {
- const pages: number[] = [];
- if (totalPages <= 7) {
- for (let i = 1; i <= totalPages; i++) pages.push(i);
- } else {
- pages.push(1);
- if (currentPage > 3) pages.push(-1);
- const start = Math.max(2, currentPage - 1);
- const end = Math.min(totalPages - 1, currentPage + 1);
- for (let i = start; i <= end; i++) pages.push(i);
- if (currentPage < totalPages - 2) pages.push(-1);
- pages.push(totalPages);
- }
- return pages;
- });
-
- function goToPage(page: number) {
- if (page >= 1 && page <= totalPages) {
- currentPage = page;
- }
- }
-
- $effect(() => {
- checkSession();
- });
-
- async function checkSession() {
- try {
- await pluginInvoke<string>("courses", "rocketseat_check_session");
- loggedIn = true;
- loadCourses();
- } catch {
- loggedIn = false;
- } finally {
- checking = false;
- }
- }
-
- async function handleTokenLogin() {
- if (!token.trim()) return;
- error = "";
- loading = true;
- try {
- await pluginInvoke<string>("courses", "rocketseat_login_token", { token: token.trim() });
- loggedIn = true;
- loadCourses();
- } catch (e: any) {
- error = typeof e === "string" ? e : e.message ?? $t('hotmart.unknown_error');
- } finally {
- loading = false;
- }
- }
-
- async function handleLogout() {
- try {
- await pluginInvoke("courses", "rocketseat_logout");
- } catch {
- }
- loggedIn = false;
- courses = [];
- coursesError = "";
- currentPage = 1;
- }
-
- let searchQuery = $state("");
-
- async function loadCourses() {
- loadingCourses = true;
- coursesError = "";
- try {
- courses = await pluginInvoke("courses", "rocketseat_list_courses");
- currentPage = 1;
- } catch (e: any) {
- coursesError = typeof e === "string" ? e : e.message ?? $t('hotmart.courses_error');
- } finally {
- loadingCourses = false;
- }
- }
-
- async function handleSearch() {
- if (!searchQuery.trim()) return;
- loadingCourses = true;
- coursesError = "";
- try {
- courses = await pluginInvoke("courses", "rocketseat_search_courses", { query: searchQuery.trim() });
- currentPage = 1;
- } catch (e: any) {
- coursesError = typeof e === "string" ? e : e.message ?? "Search failed";
- } finally {
- loadingCourses = false;
- }
- }
-
- function getCourseDownloadStatus(courseId: string): "idle" | "downloading" | "complete" | "error" {
- const numId = hashCode(courseId);
- const item = downloads.get(numId);
- if (!item) return "idle";
- const s = item.status;
- if (s === "queued" || s === "paused" || s === "seeding") return "downloading";
- return s;
- }
-
- function getCourseDownloadPercent(courseId: string): number {
- const numId = hashCode(courseId);
- return downloads.get(numId)?.percent ?? 0;
- }
-
- function hashCode(str: string): number {
- let hash = 0;
- for (let i = 0; i < str.length; i++) {
- const char = str.charCodeAt(i);
- hash = ((hash << 5) - hash) + char;
- hash |= 0;
- }
- return Math.abs(hash);
- }
-
- async function downloadCourse(course: RocketseatCourse) {
- const status = getCourseDownloadStatus(course.id);
- if (status === "downloading") {
- showToast("info", $t("toast.download_already_active"));
- return;
- }
- if (status === "complete") return;
-
- const appSettings = getSettings();
- let outputDir: string | null = null;
-
- if (appSettings?.download.always_ask_path) {
- outputDir = await open({ directory: true, title: $t("hotmart.choose_folder") }) as string | null;
- if (!outputDir) return;
- } else {
- outputDir = appSettings?.download.default_output_dir ?? null;
- if (!outputDir) {
- outputDir = await open({ directory: true, title: $t("hotmart.choose_folder") }) as string | null;
- if (!outputDir) return;
- }
- }
-
- try {
- await pluginInvoke("courses", "start_rocketseat_course_download", {
- courseJson: JSON.stringify(course),
- outputDir,
- });
- showToast("info", $t("toast.download_preparing"));
- } catch (e: any) {
- const msg = typeof e === "string" ? e : e.message ?? $t("common.error");
- showToast("error", msg);
- }
- }
-
- let refreshing = $state(false);
-
- async function refreshCourses() {
- refreshing = true;
- loadingCourses = true;
- coursesError = "";
- try {
- courses = await pluginInvoke("courses", "rocketseat_refresh_courses");
- currentPage = 1;
- } catch (e: any) {
- coursesError = typeof e === "string" ? e : e.message ?? $t('hotmart.courses_error');
- } finally {
- loadingCourses = false;
- refreshing = false;
- }
- }
-</script>
-
-<a href="/courses" class="back-link">
- <svg viewBox="0 0 24 24" width="16" height="16" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
- <path d="M19 12H5" />
- <path d="M12 19l-7-7 7-7" />
- </svg>
- {$t("courses.back")}
-</a>
-
-{#if checking}
- <div class="page-center">
- <span class="spinner"></span>
- <span class="spinner-text">{$t('hotmart.checking_session')}</span>
- </div>
-{:else if loggedIn}
- <div class="page-logged">
- <div class="session-bar">
- <span class="session-info">
- Rocketseat
- </span>
- <div class="session-actions">
- <button
- class="button"
- onclick={refreshCourses}
- disabled={refreshing}
- aria-label={$t('hotmart.refresh')}
- >
- <svg viewBox="0 0 24 24" width="14" height="14" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class:spinning={refreshing}>
- <path d="M21 2v6h-6" />
- <path d="M3 12a9 9 0 0115-6.7L21 8" />
- <path d="M3 22v-6h6" />
- <path d="M21 12a9 9 0 01-15 6.7L3 16" />
- </svg>
- </button>
- <button class="button" onclick={handleLogout}>{$t('hotmart.logout')}</button>
- </div>
- </div>
-
- <form class="search-bar" onsubmit={(e) => { e.preventDefault(); handleSearch(); }}>
- <input
- class="input search-input"
- type="text"
- placeholder="Search courses (e.g. Node, React, Java...)"
- bind:value={searchQuery}
- />
- <button class="button" type="submit" disabled={loadingCourses || !searchQuery.trim()}>
- Search
- </button>
- </form>
-
- {#if loadingCourses}
- <div class="spinner-section">
- <span class="spinner"></span>
- <span class="spinner-text">{$t('hotmart.loading_courses')}</span>
- </div>
- {:else if coursesError}
- <div class="error-section">
- <p class="error-msg">{coursesError}</p>
- <button class="button" onclick={loadCourses}>{$t('common.retry')}</button>
- </div>
- {:else if courses.length === 0}
- <p class="empty-text">{$t('hotmart.no_courses')}</p>
- {:else}
- <div class="courses-header">
- <h2>{$t('hotmart.courses_title')}</h2>
- <span class="subtext">{courses.length === 1 ? $t('hotmart.course_count_one', { count: courses.length }) : $t('hotmart.course_count', { count: courses.length })}</span>
- </div>
-
- <div class="courses-grid">
- {#each paginatedCourses as course (course.id)}
- <CourseCard
- name={course.name}
- price={course.slug}
- imageUrl={undefined}
- downloadStatus={getCourseDownloadStatus(course.id)}
- downloadPercent={getCourseDownloadPercent(course.id)}
- onDownload={() => downloadCourse(course)}
- />
- {/each}
- </div>
-
- {#if totalPages > 1}
- <div class="pagination">
- <span class="pagination-info">
- {$t('hotmart.page_of', { current: currentPage, total: totalPages })} &middot; {courses.length === 1 ? $t('hotmart.course_count_one', { count: courses.length }) : $t('hotmart.course_count', { count: courses.length })}
- </span>
- <div class="pagination-controls">
- <button
- class="button pagination-btn"
- disabled={currentPage <= 1}
- onclick={() => goToPage(currentPage - 1)}
- >
- &lt;
- </button>
-
- {#each pageNumbers() as page}
- {#if page === -1}
- <span class="pagination-ellipsis">&hellip;</span>
- {:else}
- <button
- class="button pagination-btn"
- class:active={page === currentPage}
- onclick={() => goToPage(page)}
- >
- {page}
- </button>
- {/if}
- {/each}
-
- <button
- class="button pagination-btn"
- disabled={currentPage >= totalPages}
- onclick={() => goToPage(currentPage + 1)}
- >
- &gt;
- </button>
- </div>
- </div>
- {/if}
- {/if}
- </div>
-{:else}
- <div class="page-center">
- <div class="login-card">
- <h2>Rocketseat</h2>
-
- <div class="form">
- <label class="field">
- <span class="field-label">Cookies JSON</span>
- <textarea
- class="input token-textarea"
- placeholder="Paste cookies JSON from browser extension or a raw token"
- bind:value={token}
- disabled={loading}
- rows="4"
- ></textarea>
- </label>
- <input type="file" accept=".json,.txt" class="hidden-file-input" bind:this={fileInput} onchange={onFileSelected} />
- <button class="button" onclick={() => fileInput?.click()} disabled={loading}>Import .json file</button>
-
- {#if error}
- <p class="error-msg">{error}</p>
- {/if}
-
- <button class="button" onclick={handleTokenLogin} disabled={loading || !token.trim()}>
- {#if loading}
- {$t('hotmart.authenticating')}
- {:else}
- {$t('hotmart.login')}
- {/if}
- </button>
- </div>
- </div>
- </div>
-{/if}
-
-<style>
- .search-bar {
- display: flex;
- gap: calc(var(--padding) / 2);
- width: 100%;
- }
-
- .search-input {
- flex: 1;
- }
-
- .back-link {
- display: inline-flex;
- align-items: center;
- gap: 6px;
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- margin-bottom: var(--padding);
- }
-
- @media (hover: hover) {
- .back-link:hover {
- color: var(--secondary);
- }
- }
-
- .page-center {
- display: flex;
- flex-direction: column;
- align-items: center;
- justify-content: center;
- min-height: calc(100vh - var(--padding) * 4 - 40px);
- gap: var(--padding);
- }
-
- .page-logged {
- display: flex;
- flex-direction: column;
- align-items: center;
- gap: calc(var(--padding) * 1.5);
- padding: calc(var(--padding) * 1.5);
- width: 100%;
- }
-
- .page-logged > :global(*) {
- width: 100%;
- max-width: 1200px;
- }
-
- .session-bar {
- display: flex;
- align-items: center;
- justify-content: space-between;
- }
-
- .session-info {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .session-actions {
- display: flex;
- gap: calc(var(--padding) / 2);
- }
-
- .session-bar :global(.button) {
- padding: calc(var(--padding) / 2) var(--padding);
- font-size: 12.5px;
- }
-
- .spinning {
- animation: spin 0.6s linear infinite;
- }
-
- .courses-header {
- display: flex;
- align-items: baseline;
- gap: var(--padding);
- }
-
- .courses-header h2 {
- margin-block: 0;
- }
-
- .subtext {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .courses-grid {
- display: grid;
- grid-template-columns: repeat(4, 1fr);
- gap: var(--padding);
- }
-
- @media (max-width: 1000px) {
- .courses-grid {
- grid-template-columns: repeat(3, 1fr);
- }
- }
-
- @media (max-width: 750px) {
- .courses-grid {
- grid-template-columns: repeat(2, 1fr);
- }
- }
-
- @media (max-width: 535px) {
- .courses-grid {
- grid-template-columns: 1fr;
- }
- }
-
- .pagination {
- display: flex;
- flex-direction: column;
- align-items: center;
- gap: var(--padding);
- padding-top: var(--padding);
- }
-
- .pagination-info {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .pagination-controls {
- display: flex;
- align-items: center;
- gap: calc(var(--padding) / 3);
- }
-
- .pagination-btn {
- min-width: 36px;
- height: 36px;
- padding: 0;
- display: flex;
- align-items: center;
- justify-content: center;
- font-size: 14.5px;
- }
-
- .pagination-ellipsis {
- min-width: 36px;
- text-align: center;
- color: var(--gray);
- font-size: 14.5px;
- }
-
- .login-card {
- width: 100%;
- max-width: 400px;
- background: var(--button-elevated);
- border-radius: var(--border-radius);
- padding: calc(var(--padding) * 2);
- display: flex;
- flex-direction: column;
- gap: calc(var(--padding) * 1.5);
- }
-
- .login-card h2 {
- margin-block: 0;
- }
-
- .hidden-file-input {
- display: none;
- }
-
- .token-textarea {
- resize: vertical;
- min-height: 80px;
- font-size: 11.5px;
- font-family: var(--font-mono);
- line-height: 1.5;
- }
-
- .form {
- display: flex;
- flex-direction: column;
- gap: var(--padding);
- }
-
- .field {
- display: flex;
- flex-direction: column;
- gap: calc(var(--padding) / 2);
- }
-
- .field-label {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .input {
- width: 100%;
- padding: var(--padding);
- font-size: 14.5px;
- background: var(--button);
- border-radius: var(--border-radius);
- color: var(--secondary);
- border: 1px solid var(--input-border);
- }
-
- .input::placeholder {
- color: var(--gray);
- }
-
- .input:focus-visible {
- border-color: var(--secondary);
- outline: none;
- }
-
- .input:disabled {
- opacity: 0.5;
- cursor: default;
- }
-
- .error-msg {
- color: var(--red);
- font-size: 12.5px;
- font-weight: 500;
- }
-
- .spinner-section {
- display: flex;
- flex-direction: column;
- align-items: center;
- gap: var(--padding);
- padding: calc(var(--padding) * 4) 0;
- }
-
- .spinner {
- width: 24px;
- height: 24px;
- border: 2px solid var(--input-border);
- border-top-color: var(--blue);
- border-radius: 50%;
- animation: spin 0.6s linear infinite;
- }
-
- @keyframes spin {
- to {
- transform: rotate(360deg);
- }
- }
-
- .spinner-text {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .error-section {
- display: flex;
- flex-direction: column;
- align-items: center;
- gap: var(--padding);
- padding: calc(var(--padding) * 2) 0;
- }
-
- .empty-text {
- color: var(--gray);
- font-size: 14.5px;
- text-align: center;
- padding: calc(var(--padding) * 4) 0;
- }
-</style>
diff --git a/src/routes/courses/skool/+page.svelte b/src/routes/courses/skool/+page.svelte
deleted file mode 100644
index 0bc1efdf..00000000
--- a/src/routes/courses/skool/+page.svelte
+++ /dev/null
@@ -1,693 +0,0 @@
-<script lang="ts">
- import { pluginInvoke } from "$lib/plugin-invoke";
- import { open } from "@tauri-apps/plugin-dialog";
- import CourseCard from "$components/hotmart/CourseCard.svelte";
- import { showToast } from "$lib/stores/toast-store.svelte";
- import { getDownloads } from "$lib/stores/download-store.svelte";
- import { getSettings } from "$lib/stores/settings-store.svelte";
- import { t } from "$lib/i18n";
-
- let downloads = $derived(getDownloads());
-
- type SkoolGroup = {
- id: string;
- slug: string;
- name: string;
- image_url: string | null;
- num_courses: number;
- };
-
- let email = $state("");
- let password = $state("");
- let token = $state("");
- let fileInput: HTMLInputElement = $state() as HTMLInputElement;
- function onFileSelected(e: Event) {
- const input = e.target as HTMLInputElement;
- const file = input.files?.[0];
- if (!file) return;
- const reader = new FileReader();
- reader.onload = () => { token = reader.result as string; };
- reader.readAsText(file);
- input.value = "";
- }
- let loading = $state(false);
- let error = $state("");
-
- let checking = $state(true);
- let loggedIn = $state(false);
- let sessionEmail = $state("");
-
- let loginMode = $state<"credentials" | "token">("credentials");
-
- let courses: SkoolGroup[] = $state([]);
- let loadingCourses = $state(false);
- let coursesError = $state("");
-
- const ITEMS_PER_PAGE = 12;
- let currentPage = $state(1);
-
- let totalPages = $derived(Math.max(1, Math.ceil(courses.length / ITEMS_PER_PAGE)));
- let paginatedCourses = $derived(
- courses.slice((currentPage - 1) * ITEMS_PER_PAGE, currentPage * ITEMS_PER_PAGE)
- );
-
- let pageNumbers = $derived((): number[] => {
- const pages: number[] = [];
- if (totalPages <= 7) {
- for (let i = 1; i <= totalPages; i++) pages.push(i);
- } else {
- pages.push(1);
- if (currentPage > 3) pages.push(-1);
- const start = Math.max(2, currentPage - 1);
- const end = Math.min(totalPages - 1, currentPage + 1);
- for (let i = start; i <= end; i++) pages.push(i);
- if (currentPage < totalPages - 2) pages.push(-1);
- pages.push(totalPages);
- }
- return pages;
- });
-
- function goToPage(page: number) {
- if (page >= 1 && page <= totalPages) {
- currentPage = page;
- }
- }
-
- $effect(() => {
- checkSession();
- });
-
- async function checkSession() {
- try {
- const result = await pluginInvoke<string>("courses", "skool_check_session");
- sessionEmail = result;
- loggedIn = true;
- loadCourses();
- } catch {
- loggedIn = false;
- } finally {
- checking = false;
- }
- }
-
- async function handleLogin() {
- error = "";
- loading = true;
- try {
- const result = await pluginInvoke<string>("courses", "skool_login", { email, password });
- sessionEmail = result || email;
- loggedIn = true;
- loadCourses();
- } catch (e: any) {
- error = typeof e === "string" ? e : e.message ?? $t('hotmart.unknown_error');
- } finally {
- loading = false;
- }
- }
-
- async function handleTokenLogin() {
- if (!token.trim()) return;
- error = "";
- loading = true;
- try {
- const result = await pluginInvoke<string>("courses", "skool_login_token", { token: token.trim() });
- sessionEmail = result || "Token";
- loggedIn = true;
- loadCourses();
- } catch (e: any) {
- error = typeof e === "string" ? e : e.message ?? $t('hotmart.unknown_error');
- } finally {
- loading = false;
- }
- }
-
- async function handleLogout() {
- try {
- await pluginInvoke("courses", "skool_logout");
- } catch {
- }
- loggedIn = false;
- sessionEmail = "";
- courses = [];
- coursesError = "";
- currentPage = 1;
- }
-
- async function loadCourses() {
- loadingCourses = true;
- coursesError = "";
- try {
- courses = await pluginInvoke("courses", "skool_list_groups");
- currentPage = 1;
- } catch (e: any) {
- coursesError = typeof e === "string" ? e : e.message ?? $t('hotmart.courses_error');
- } finally {
- loadingCourses = false;
- }
- }
-
- function getCourseDownloadStatus(courseId: string): "idle" | "downloading" | "complete" | "error" {
- const item = downloads.get(Number(courseId) || 0);
- if (!item) return "idle";
- const s = item.status;
- if (s === "queued" || s === "paused" || s === "seeding") return "downloading";
- return s;
- }
-
- function getCourseDownloadPercent(courseId: string): number {
- return downloads.get(Number(courseId) || 0)?.percent ?? 0;
- }
-
- async function downloadCourse(group: SkoolGroup) {
- const status = getCourseDownloadStatus(group.id);
- if (status === "downloading") {
- showToast("info", $t("toast.download_already_active"));
- return;
- }
- if (status === "complete") return;
-
- const appSettings = getSettings();
- let outputDir: string | null = null;
-
- if (appSettings?.download.always_ask_path) {
- outputDir = await open({ directory: true, title: $t("hotmart.choose_folder") }) as string | null;
- if (!outputDir) return;
- } else {
- outputDir = appSettings?.download.default_output_dir ?? null;
- if (!outputDir) {
- outputDir = await open({ directory: true, title: $t("hotmart.choose_folder") }) as string | null;
- if (!outputDir) return;
- }
- }
-
- try {
- await pluginInvoke("courses", "start_skool_course_download", {
- courseJson: JSON.stringify(group),
- outputDir,
- });
- showToast("info", $t("toast.download_preparing"));
- } catch (e: any) {
- const msg = typeof e === "string" ? e : e.message ?? $t("common.error");
- showToast("error", msg);
- }
- }
-
- let refreshing = $state(false);
-
- async function refreshCourses() {
- refreshing = true;
- loadingCourses = true;
- coursesError = "";
- try {
- courses = await pluginInvoke("courses", "skool_refresh_groups");
- currentPage = 1;
- } catch (e: any) {
- coursesError = typeof e === "string" ? e : e.message ?? $t('hotmart.courses_error');
- } finally {
- loadingCourses = false;
- refreshing = false;
- }
- }
-</script>
-
-<a href="/courses" class="back-link">
- <svg viewBox="0 0 24 24" width="16" height="16" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
- <path d="M19 12H5" />
- <path d="M12 19l-7-7 7-7" />
- </svg>
- {$t("courses.back")}
-</a>
-
-{#if checking}
- <div class="page-center">
- <span class="spinner"></span>
- <span class="spinner-text">{$t('hotmart.checking_session')}</span>
- </div>
-{:else if loggedIn}
- <div class="page-logged">
- <div class="session-bar">
- <span class="session-info">
- {$t('hotmart.logged_as', { email: sessionEmail || "—" })}
- </span>
- <div class="session-actions">
- <button
- class="button"
- onclick={refreshCourses}
- disabled={refreshing}
- aria-label={$t('hotmart.refresh')}
- >
- <svg viewBox="0 0 24 24" width="14" height="14" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class:spinning={refreshing}>
- <path d="M21 2v6h-6" />
- <path d="M3 12a9 9 0 0115-6.7L21 8" />
- <path d="M3 22v-6h6" />
- <path d="M21 12a9 9 0 01-15 6.7L3 16" />
- </svg>
- </button>
- <button class="button" onclick={handleLogout}>{$t('hotmart.logout')}</button>
- </div>
- </div>
-
- {#if loadingCourses}
- <div class="spinner-section">
- <span class="spinner"></span>
- <span class="spinner-text">{$t('hotmart.loading_courses')}</span>
- </div>
- {:else if coursesError}
- <div class="error-section">
- <p class="error-msg">{coursesError}</p>
- <button class="button" onclick={loadCourses}>{$t('common.retry')}</button>
- </div>
- {:else if courses.length === 0}
- <p class="empty-text">{$t('hotmart.no_courses')}</p>
- {:else}
- <div class="courses-header">
- <h2>{$t('hotmart.courses_title')}</h2>
- <span class="subtext">{courses.length === 1 ? $t('hotmart.course_count_one', { count: courses.length }) : $t('hotmart.course_count', { count: courses.length })}</span>
- </div>
-
- <div class="courses-grid">
- {#each paginatedCourses as group (group.id)}
- <CourseCard
- name={group.name}
- price={`${group.num_courses} courses`}
- imageUrl={group.image_url ?? undefined}
- downloadStatus={getCourseDownloadStatus(group.id)}
- downloadPercent={getCourseDownloadPercent(group.id)}
- onDownload={() => downloadCourse(group)}
- />
- {/each}
- </div>
-
- {#if totalPages > 1}
- <div class="pagination">
- <span class="pagination-info">
- {$t('hotmart.page_of', { current: currentPage, total: totalPages })} &middot; {courses.length === 1 ? $t('hotmart.course_count_one', { count: courses.length }) : $t('hotmart.course_count', { count: courses.length })}
- </span>
- <div class="pagination-controls">
- <button
- class="button pagination-btn"
- disabled={currentPage <= 1}
- onclick={() => goToPage(currentPage - 1)}
- >
- &lt;
- </button>
-
- {#each pageNumbers() as page}
- {#if page === -1}
- <span class="pagination-ellipsis">&hellip;</span>
- {:else}
- <button
- class="button pagination-btn"
- class:active={page === currentPage}
- onclick={() => goToPage(page)}
- >
- {page}
- </button>
- {/if}
- {/each}
-
- <button
- class="button pagination-btn"
- disabled={currentPage >= totalPages}
- onclick={() => goToPage(currentPage + 1)}
- >
- &gt;
- </button>
- </div>
- </div>
- {/if}
- {/if}
- </div>
-{:else}
- <div class="page-center">
- <div class="login-card">
- <h2>Skool</h2>
-
- <div class="login-tabs">
- <button
- class="button login-tab"
- class:active={loginMode === "credentials"}
- onclick={() => { loginMode = "credentials"; error = ""; }}
- >
- Email & Password
- </button>
- <button
- class="button login-tab"
- class:active={loginMode === "token"}
- onclick={() => { loginMode = "token"; error = ""; }}
- >
- Token
- </button>
- </div>
-
- {#if loginMode === "credentials"}
- <form class="form" onsubmit={(e) => { e.preventDefault(); handleLogin(); }}>
- <label class="field">
- <span class="field-label">{$t('hotmart.email_label')}</span>
- <input
- type="email"
- placeholder={$t('hotmart.email_placeholder')}
- bind:value={email}
- class="input"
- disabled={loading}
- required
- />
- </label>
- <label class="field">
- <span class="field-label">{$t('hotmart.password_label')}</span>
- <input
- type="password"
- placeholder={$t('hotmart.password_placeholder')}
- bind:value={password}
- class="input"
- disabled={loading}
- required
- />
- </label>
-
- {#if error}
- <p class="error-msg">{error}</p>
- {/if}
-
- <button type="submit" class="button" disabled={loading}>
- {#if loading}
- {$t('hotmart.authenticating')}
- {:else}
- {$t('hotmart.login')}
- {/if}
- </button>
- </form>
- {:else}
- <div class="form">
- <label class="field">
- <span class="field-label">Cookies JSON</span>
- <textarea
- class="input token-textarea"
- placeholder="Paste cookies JSON from browser extension or a raw token"
- bind:value={token}
- disabled={loading}
- rows="4"
- ></textarea>
- </label>
- <input type="file" accept=".json,.txt" class="hidden-file-input" bind:this={fileInput} onchange={onFileSelected} />
- <button class="button" onclick={() => fileInput?.click()} disabled={loading}>Import .json file</button>
-
- {#if error}
- <p class="error-msg">{error}</p>
- {/if}
-
- <button class="button" onclick={handleTokenLogin} disabled={loading || !token.trim()}>
- {#if loading}
- {$t('hotmart.authenticating')}
- {:else}
- {$t('hotmart.login')}
- {/if}
- </button>
- </div>
- {/if}
- </div>
- </div>
-{/if}
-
-<style>
- .back-link {
- display: inline-flex;
- align-items: center;
- gap: 6px;
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- margin-bottom: var(--padding);
- }
-
- @media (hover: hover) {
- .back-link:hover {
- color: var(--secondary);
- }
- }
-
- .page-center {
- display: flex;
- flex-direction: column;
- align-items: center;
- justify-content: center;
- min-height: calc(100vh - var(--padding) * 4 - 40px);
- gap: var(--padding);
- }
-
- .page-logged {
- display: flex;
- flex-direction: column;
- align-items: center;
- gap: calc(var(--padding) * 1.5);
- padding: calc(var(--padding) * 1.5);
- width: 100%;
- }
-
- .page-logged > :global(*) {
- width: 100%;
- max-width: 1200px;
- }
-
- .session-bar {
- display: flex;
- align-items: center;
- justify-content: space-between;
- }
-
- .session-info {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .session-actions {
- display: flex;
- gap: calc(var(--padding) / 2);
- }
-
- .session-bar :global(.button) {
- padding: calc(var(--padding) / 2) var(--padding);
- font-size: 12.5px;
- }
-
- .spinning {
- animation: spin 0.6s linear infinite;
- }
-
- .courses-header {
- display: flex;
- align-items: baseline;
- gap: var(--padding);
- }
-
- .courses-header h2 {
- margin-block: 0;
- }
-
- .subtext {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .courses-grid {
- display: grid;
- grid-template-columns: repeat(4, 1fr);
- gap: var(--padding);
- }
-
- @media (max-width: 1000px) {
- .courses-grid {
- grid-template-columns: repeat(3, 1fr);
- }
- }
-
- @media (max-width: 750px) {
- .courses-grid {
- grid-template-columns: repeat(2, 1fr);
- }
- }
-
- @media (max-width: 535px) {
- .courses-grid {
- grid-template-columns: 1fr;
- }
- }
-
- .pagination {
- display: flex;
- flex-direction: column;
- align-items: center;
- gap: var(--padding);
- padding-top: var(--padding);
- }
-
- .pagination-info {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .pagination-controls {
- display: flex;
- align-items: center;
- gap: calc(var(--padding) / 3);
- }
-
- .pagination-btn {
- min-width: 36px;
- height: 36px;
- padding: 0;
- display: flex;
- align-items: center;
- justify-content: center;
- font-size: 14.5px;
- }
-
- .pagination-ellipsis {
- min-width: 36px;
- text-align: center;
- color: var(--gray);
- font-size: 14.5px;
- }
-
- .login-card {
- width: 100%;
- max-width: 400px;
- background: var(--button-elevated);
- border-radius: var(--border-radius);
- padding: calc(var(--padding) * 2);
- display: flex;
- flex-direction: column;
- gap: calc(var(--padding) * 1.5);
- }
-
- .login-card h2 {
- margin-block: 0;
- }
-
- .login-tabs {
- display: flex;
- gap: 0;
- }
-
- .login-tab {
- flex: 1;
- border-radius: 0;
- font-size: 12.5px;
- padding: calc(var(--padding) * 0.75) var(--padding);
- }
-
- .login-tab:first-child {
- border-radius: var(--border-radius) 0 0 var(--border-radius);
- }
-
- .login-tab:last-child {
- border-radius: 0 var(--border-radius) var(--border-radius) 0;
- }
-
- .hidden-file-input {
- display: none;
- }
-
- .token-textarea {
- resize: vertical;
- min-height: 80px;
- font-size: 11.5px;
- font-family: var(--font-mono);
- line-height: 1.5;
- }
-
- .form {
- display: flex;
- flex-direction: column;
- gap: var(--padding);
- }
-
- .field {
- display: flex;
- flex-direction: column;
- gap: calc(var(--padding) / 2);
- }
-
- .field-label {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .input {
- width: 100%;
- padding: var(--padding);
- font-size: 14.5px;
- background: var(--button);
- border-radius: var(--border-radius);
- color: var(--secondary);
- border: 1px solid var(--input-border);
- }
-
- .input::placeholder {
- color: var(--gray);
- }
-
- .input:focus-visible {
- border-color: var(--secondary);
- outline: none;
- }
-
- .input:disabled {
- opacity: 0.5;
- cursor: default;
- }
-
- .error-msg {
- color: var(--red);
- font-size: 12.5px;
- font-weight: 500;
- }
-
- .spinner-section {
- display: flex;
- flex-direction: column;
- align-items: center;
- gap: var(--padding);
- padding: calc(var(--padding) * 4) 0;
- }
-
- .spinner {
- width: 24px;
- height: 24px;
- border: 2px solid var(--input-border);
- border-top-color: var(--blue);
- border-radius: 50%;
- animation: spin 0.6s linear infinite;
- }
-
- @keyframes spin {
- to {
- transform: rotate(360deg);
- }
- }
-
- .spinner-text {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .error-section {
- display: flex;
- flex-direction: column;
- align-items: center;
- gap: var(--padding);
- padding: calc(var(--padding) * 2) 0;
- }
-
- .empty-text {
- color: var(--gray);
- font-size: 14.5px;
- text-align: center;
- padding: calc(var(--padding) * 4) 0;
- }
-</style>
diff --git a/src/routes/courses/teachable/+page.svelte b/src/routes/courses/teachable/+page.svelte
deleted file mode 100644
index 107f8886..00000000
--- a/src/routes/courses/teachable/+page.svelte
+++ /dev/null
@@ -1,597 +0,0 @@
-<script lang="ts">
- import { pluginInvoke } from "$lib/plugin-invoke";
- import { open } from "@tauri-apps/plugin-dialog";
- import CourseCard from "$components/hotmart/CourseCard.svelte";
- import { showToast } from "$lib/stores/toast-store.svelte";
- import { getDownloads } from "$lib/stores/download-store.svelte";
- import { getSettings } from "$lib/stores/settings-store.svelte";
- import { t } from "$lib/i18n";
-
- let downloads = $derived(getDownloads());
-
- type TeachableCourse = {
- id: string;
- name: string;
- image_url: string | null;
- school_id: string;
- };
-
- let token = $state("");
- let fileInput: HTMLInputElement = $state() as HTMLInputElement;
- function onFileSelected(e: Event) {
- const input = e.target as HTMLInputElement;
- const file = input.files?.[0];
- if (!file) return;
- const reader = new FileReader();
- reader.onload = () => { token = reader.result as string; };
- reader.readAsText(file);
- input.value = "";
- }
- let loading = $state(false);
- let error = $state("");
-
- let checking = $state(true);
- let loggedIn = $state(false);
- let sessionEmail = $state("");
-
- let courses: TeachableCourse[] = $state([]);
- let loadingCourses = $state(false);
- let coursesError = $state("");
-
- const ITEMS_PER_PAGE = 12;
- let currentPage = $state(1);
-
- let totalPages = $derived(Math.max(1, Math.ceil(courses.length / ITEMS_PER_PAGE)));
- let paginatedCourses = $derived(
- courses.slice((currentPage - 1) * ITEMS_PER_PAGE, currentPage * ITEMS_PER_PAGE)
- );
-
- let pageNumbers = $derived((): number[] => {
- const pages: number[] = [];
- if (totalPages <= 7) {
- for (let i = 1; i <= totalPages; i++) pages.push(i);
- } else {
- pages.push(1);
- if (currentPage > 3) pages.push(-1);
- const start = Math.max(2, currentPage - 1);
- const end = Math.min(totalPages - 1, currentPage + 1);
- for (let i = start; i <= end; i++) pages.push(i);
- if (currentPage < totalPages - 2) pages.push(-1);
- pages.push(totalPages);
- }
- return pages;
- });
-
- function goToPage(page: number) {
- if (page >= 1 && page <= totalPages) {
- currentPage = page;
- }
- }
-
- $effect(() => {
- checkSession();
- });
-
- async function checkSession() {
- try {
- const result = await pluginInvoke<string>("courses", "teachable_check_session");
- sessionEmail = result;
- loggedIn = true;
- loadCourses();
- } catch {
- loggedIn = false;
- } finally {
- checking = false;
- }
- }
-
- async function handleTokenLogin() {
- if (!token.trim()) return;
- error = "";
- loading = true;
- try {
- const result = await pluginInvoke<string>("courses", "teachable_login_token", { token: token.trim() });
- sessionEmail = result || "Token";
- loggedIn = true;
- loadCourses();
- } catch (e: any) {
- error = typeof e === "string" ? e : e.message ?? $t('hotmart.unknown_error');
- } finally {
- loading = false;
- }
- }
-
- async function handleLogout() {
- try {
- await pluginInvoke("courses", "teachable_logout");
- } catch {
- }
- loggedIn = false;
- sessionEmail = "";
- courses = [];
- coursesError = "";
- currentPage = 1;
- }
-
- async function loadCourses() {
- loadingCourses = true;
- coursesError = "";
- try {
- courses = await pluginInvoke("courses", "teachable_list_courses");
- currentPage = 1;
- } catch (e: any) {
- coursesError = typeof e === "string" ? e : e.message ?? $t('hotmart.courses_error');
- } finally {
- loadingCourses = false;
- }
- }
-
- function getCourseDownloadStatus(courseId: string): "idle" | "downloading" | "complete" | "error" {
- const item = downloads.get(Number(courseId) || 0);
- if (!item) return "idle";
- const s = item.status;
- if (s === "queued" || s === "paused" || s === "seeding") return "downloading";
- return s;
- }
-
- function getCourseDownloadPercent(courseId: string): number {
- return downloads.get(Number(courseId) || 0)?.percent ?? 0;
- }
-
- async function downloadCourse(course: TeachableCourse) {
- const status = getCourseDownloadStatus(course.id);
- if (status === "downloading") {
- showToast("info", $t("toast.download_already_active"));
- return;
- }
- if (status === "complete") return;
-
- const appSettings = getSettings();
- let outputDir: string | null = null;
-
- if (appSettings?.download.always_ask_path) {
- outputDir = await open({ directory: true, title: $t("hotmart.choose_folder") }) as string | null;
- if (!outputDir) return;
- } else {
- outputDir = appSettings?.download.default_output_dir ?? null;
- if (!outputDir) {
- outputDir = await open({ directory: true, title: $t("hotmart.choose_folder") }) as string | null;
- if (!outputDir) return;
- }
- }
-
- try {
- await pluginInvoke("courses", "start_teachable_course_download", {
- courseJson: JSON.stringify(course),
- outputDir,
- });
- showToast("info", $t("toast.download_preparing"));
- } catch (e: any) {
- const msg = typeof e === "string" ? e : e.message ?? $t("common.error");
- showToast("error", msg);
- }
- }
-
- let refreshing = $state(false);
-
- async function refreshCourses() {
- refreshing = true;
- loadingCourses = true;
- coursesError = "";
- try {
- courses = await pluginInvoke("courses", "teachable_refresh_courses");
- currentPage = 1;
- } catch (e: any) {
- coursesError = typeof e === "string" ? e : e.message ?? $t('hotmart.courses_error');
- } finally {
- loadingCourses = false;
- refreshing = false;
- }
- }
-</script>
-
-<a href="/courses" class="back-link">
- <svg viewBox="0 0 24 24" width="16" height="16" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
- <path d="M19 12H5" />
- <path d="M12 19l-7-7 7-7" />
- </svg>
- {$t("courses.back")}
-</a>
-
-{#if checking}
- <div class="page-center">
- <span class="spinner"></span>
- <span class="spinner-text">{$t('hotmart.checking_session')}</span>
- </div>
-{:else if loggedIn}
- <div class="page-logged">
- <div class="session-bar">
- <span class="session-info">
- {$t('hotmart.logged_as', { email: sessionEmail || "—" })}
- </span>
- <div class="session-actions">
- <button
- class="button"
- onclick={refreshCourses}
- disabled={refreshing}
- aria-label={$t('hotmart.refresh')}
- >
- <svg viewBox="0 0 24 24" width="14" height="14" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class:spinning={refreshing}>
- <path d="M21 2v6h-6" />
- <path d="M3 12a9 9 0 0115-6.7L21 8" />
- <path d="M3 22v-6h6" />
- <path d="M21 12a9 9 0 01-15 6.7L3 16" />
- </svg>
- </button>
- <button class="button" onclick={handleLogout}>{$t('hotmart.logout')}</button>
- </div>
- </div>
-
- {#if loadingCourses}
- <div class="spinner-section">
- <span class="spinner"></span>
- <span class="spinner-text">{$t('hotmart.loading_courses')}</span>
- </div>
- {:else if coursesError}
- <div class="error-section">
- <p class="error-msg">{coursesError}</p>
- <button class="button" onclick={loadCourses}>{$t('common.retry')}</button>
- </div>
- {:else if courses.length === 0}
- <p class="empty-text">{$t('hotmart.no_courses')}</p>
- {:else}
- <div class="courses-header">
- <h2>{$t('hotmart.courses_title')}</h2>
- <span class="subtext">{courses.length === 1 ? $t('hotmart.course_count_one', { count: courses.length }) : $t('hotmart.course_count', { count: courses.length })}</span>
- </div>
-
- <div class="courses-grid">
- {#each paginatedCourses as course (course.id)}
- <CourseCard
- name={course.name}
- price=""
- imageUrl={course.image_url ?? undefined}
- downloadStatus={getCourseDownloadStatus(course.id)}
- downloadPercent={getCourseDownloadPercent(course.id)}
- onDownload={() => downloadCourse(course)}
- />
- {/each}
- </div>
-
- {#if totalPages > 1}
- <div class="pagination">
- <span class="pagination-info">
- {$t('hotmart.page_of', { current: currentPage, total: totalPages })} &middot; {courses.length === 1 ? $t('hotmart.course_count_one', { count: courses.length }) : $t('hotmart.course_count', { count: courses.length })}
- </span>
- <div class="pagination-controls">
- <button
- class="button pagination-btn"
- disabled={currentPage <= 1}
- onclick={() => goToPage(currentPage - 1)}
- >
- &lt;
- </button>
-
- {#each pageNumbers() as page}
- {#if page === -1}
- <span class="pagination-ellipsis">&hellip;</span>
- {:else}
- <button
- class="button pagination-btn"
- class:active={page === currentPage}
- onclick={() => goToPage(page)}
- >
- {page}
- </button>
- {/if}
- {/each}
-
- <button
- class="button pagination-btn"
- disabled={currentPage >= totalPages}
- onclick={() => goToPage(currentPage + 1)}
- >
- &gt;
- </button>
- </div>
- </div>
- {/if}
- {/if}
- </div>
-{:else}
- <div class="page-center">
- <div class="login-card">
- <h2>Teachable</h2>
-
- <div class="form">
- <label class="field">
- <span class="field-label">Cookies JSON</span>
- <textarea
- class="input token-textarea"
- placeholder="Paste cookies JSON from browser extension or a raw token"
- bind:value={token}
- disabled={loading}
- rows="4"
- ></textarea>
- </label>
- <input type="file" accept=".json,.txt" class="hidden-file-input" bind:this={fileInput} onchange={onFileSelected} />
- <button class="button" onclick={() => fileInput?.click()} disabled={loading}>Import .json file</button>
-
- {#if error}
- <p class="error-msg">{error}</p>
- {/if}
-
- <button class="button" onclick={handleTokenLogin} disabled={loading || !token.trim()}>
- {#if loading}
- {$t('hotmart.authenticating')}
- {:else}
- {$t('hotmart.login')}
- {/if}
- </button>
- </div>
- </div>
- </div>
-{/if}
-
-<style>
- .back-link {
- display: inline-flex;
- align-items: center;
- gap: 6px;
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- margin-bottom: var(--padding);
- }
-
- @media (hover: hover) {
- .back-link:hover {
- color: var(--secondary);
- }
- }
-
- .page-center {
- display: flex;
- flex-direction: column;
- align-items: center;
- justify-content: center;
- min-height: calc(100vh - var(--padding) * 4 - 40px);
- gap: var(--padding);
- }
-
- .page-logged {
- display: flex;
- flex-direction: column;
- align-items: center;
- gap: calc(var(--padding) * 1.5);
- padding: calc(var(--padding) * 1.5);
- width: 100%;
- }
-
- .page-logged > :global(*) {
- width: 100%;
- max-width: 1200px;
- }
-
- .session-bar {
- display: flex;
- align-items: center;
- justify-content: space-between;
- }
-
- .session-info {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .session-actions {
- display: flex;
- gap: calc(var(--padding) / 2);
- }
-
- .session-bar :global(.button) {
- padding: calc(var(--padding) / 2) var(--padding);
- font-size: 12.5px;
- }
-
- .spinning {
- animation: spin 0.6s linear infinite;
- }
-
- .courses-header {
- display: flex;
- align-items: baseline;
- gap: var(--padding);
- }
-
- .courses-header h2 {
- margin-block: 0;
- }
-
- .subtext {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .courses-grid {
- display: grid;
- grid-template-columns: repeat(4, 1fr);
- gap: var(--padding);
- }
-
- @media (max-width: 1000px) {
- .courses-grid {
- grid-template-columns: repeat(3, 1fr);
- }
- }
-
- @media (max-width: 750px) {
- .courses-grid {
- grid-template-columns: repeat(2, 1fr);
- }
- }
-
- @media (max-width: 535px) {
- .courses-grid {
- grid-template-columns: 1fr;
- }
- }
-
- .pagination {
- display: flex;
- flex-direction: column;
- align-items: center;
- gap: var(--padding);
- padding-top: var(--padding);
- }
-
- .pagination-info {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .pagination-controls {
- display: flex;
- align-items: center;
- gap: calc(var(--padding) / 3);
- }
-
- .pagination-btn {
- min-width: 36px;
- height: 36px;
- padding: 0;
- display: flex;
- align-items: center;
- justify-content: center;
- font-size: 14.5px;
- }
-
- .pagination-ellipsis {
- min-width: 36px;
- text-align: center;
- color: var(--gray);
- font-size: 14.5px;
- }
-
- .login-card {
- width: 100%;
- max-width: 400px;
- background: var(--button-elevated);
- border-radius: var(--border-radius);
- padding: calc(var(--padding) * 2);
- display: flex;
- flex-direction: column;
- gap: calc(var(--padding) * 1.5);
- }
-
- .login-card h2 {
- margin-block: 0;
- }
-
- .hidden-file-input {
- display: none;
- }
-
- .token-textarea {
- resize: vertical;
- min-height: 80px;
- font-size: 11.5px;
- font-family: var(--font-mono);
- line-height: 1.5;
- }
-
- .form {
- display: flex;
- flex-direction: column;
- gap: var(--padding);
- }
-
- .field {
- display: flex;
- flex-direction: column;
- gap: calc(var(--padding) / 2);
- }
-
- .field-label {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .input {
- width: 100%;
- padding: var(--padding);
- font-size: 14.5px;
- background: var(--button);
- border-radius: var(--border-radius);
- color: var(--secondary);
- border: 1px solid var(--input-border);
- }
-
- .input::placeholder {
- color: var(--gray);
- }
-
- .input:focus-visible {
- border-color: var(--secondary);
- outline: none;
- }
-
- .input:disabled {
- opacity: 0.5;
- cursor: default;
- }
-
- .error-msg {
- color: var(--red);
- font-size: 12.5px;
- font-weight: 500;
- }
-
- .spinner-section {
- display: flex;
- flex-direction: column;
- align-items: center;
- gap: var(--padding);
- padding: calc(var(--padding) * 4) 0;
- }
-
- .spinner {
- width: 24px;
- height: 24px;
- border: 2px solid var(--input-border);
- border-top-color: var(--blue);
- border-radius: 50%;
- animation: spin 0.6s linear infinite;
- }
-
- @keyframes spin {
- to {
- transform: rotate(360deg);
- }
- }
-
- .spinner-text {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .error-section {
- display: flex;
- flex-direction: column;
- align-items: center;
- gap: var(--padding);
- padding: calc(var(--padding) * 2) 0;
- }
-
- .empty-text {
- color: var(--gray);
- font-size: 14.5px;
- text-align: center;
- padding: calc(var(--padding) * 4) 0;
- }
-</style>
diff --git a/src/routes/courses/themembers/+page.svelte b/src/routes/courses/themembers/+page.svelte
deleted file mode 100644
index 53cfc105..00000000
--- a/src/routes/courses/themembers/+page.svelte
+++ /dev/null
@@ -1,727 +0,0 @@
-<script lang="ts">
- import { pluginInvoke } from "$lib/plugin-invoke";
- import { open } from "@tauri-apps/plugin-dialog";
- import CourseCard from "$components/hotmart/CourseCard.svelte";
- import { showToast } from "$lib/stores/toast-store.svelte";
- import { getDownloads } from "$lib/stores/download-store.svelte";
- import { getSettings } from "$lib/stores/settings-store.svelte";
- import { t } from "$lib/i18n";
-
- let downloads = $derived(getDownloads());
-
- type TheMembersCourse = {
- id: number;
- name: string;
- };
-
- let email = $state("");
- let password = $state("");
- let token = $state("");
- let domain = $state("");
- let loading = $state(false);
- let error = $state("");
-
- let checking = $state(true);
- let loggedIn = $state(false);
- let sessionEmail = $state("");
-
- let loginMode = $state<"credentials" | "token">("credentials");
-
- let fileInput: HTMLInputElement = $state() as HTMLInputElement;
-
- function onFileSelected(e: Event) {
- const input = e.target as HTMLInputElement;
- const file = input.files?.[0];
- if (!file) return;
- const reader = new FileReader();
- reader.onload = () => { token = reader.result as string; };
- reader.readAsText(file);
- input.value = "";
- }
-
- let courses: TheMembersCourse[] = $state([]);
- let loadingCourses = $state(false);
- let coursesError = $state("");
-
- const ITEMS_PER_PAGE = 12;
- let currentPage = $state(1);
-
- let totalPages = $derived(Math.max(1, Math.ceil(courses.length / ITEMS_PER_PAGE)));
- let paginatedCourses = $derived(
- courses.slice((currentPage - 1) * ITEMS_PER_PAGE, currentPage * ITEMS_PER_PAGE)
- );
-
- let pageNumbers = $derived((): number[] => {
- const pages: number[] = [];
- if (totalPages <= 7) {
- for (let i = 1; i <= totalPages; i++) pages.push(i);
- } else {
- pages.push(1);
- if (currentPage > 3) pages.push(-1);
- const start = Math.max(2, currentPage - 1);
- const end = Math.min(totalPages - 1, currentPage + 1);
- for (let i = start; i <= end; i++) pages.push(i);
- if (currentPage < totalPages - 2) pages.push(-1);
- pages.push(totalPages);
- }
- return pages;
- });
-
- function goToPage(page: number) {
- if (page >= 1 && page <= totalPages) {
- currentPage = page;
- }
- }
-
- $effect(() => {
- checkSession();
- });
-
- async function checkSession() {
- try {
- const result = await pluginInvoke<string>("courses", "themembers_check_session");
- sessionEmail = result;
- loggedIn = true;
- loadCourses();
- } catch {
- loggedIn = false;
- } finally {
- checking = false;
- }
- }
-
- async function handleLogin() {
- error = "";
- loading = true;
- try {
- const result = await pluginInvoke<string>("courses", "themembers_login", {
- email,
- password,
- domain: domain.trim(),
- });
- sessionEmail = result || email;
- loggedIn = true;
- loadCourses();
- } catch (e: any) {
- error = typeof e === "string" ? e : e.message ?? $t('hotmart.unknown_error');
- } finally {
- loading = false;
- }
- }
-
- async function handleTokenLogin() {
- if (!token.trim()) return;
- error = "";
- loading = true;
- try {
- const result = await pluginInvoke<string>("courses", "themembers_login_token", {
- token: token.trim(),
- domain: domain.trim(),
- });
- sessionEmail = result || "Token";
- loggedIn = true;
- loadCourses();
- } catch (e: any) {
- error = typeof e === "string" ? e : e.message ?? $t('hotmart.unknown_error');
- } finally {
- loading = false;
- }
- }
-
- async function handleLogout() {
- try {
- await pluginInvoke("courses", "themembers_logout");
- } catch {
- }
- loggedIn = false;
- sessionEmail = "";
- courses = [];
- coursesError = "";
- currentPage = 1;
- }
-
- async function loadCourses() {
- loadingCourses = true;
- coursesError = "";
- try {
- courses = await pluginInvoke("courses", "themembers_list_courses");
- currentPage = 1;
- } catch (e: any) {
- coursesError = typeof e === "string" ? e : e.message ?? $t('hotmart.courses_error');
- } finally {
- loadingCourses = false;
- }
- }
-
- function getCourseDownloadStatus(courseId: number): "idle" | "downloading" | "complete" | "error" {
- const item = downloads.get(courseId);
- if (!item) return "idle";
- const s = item.status;
- if (s === "queued" || s === "paused" || s === "seeding") return "downloading";
- return s;
- }
-
- function getCourseDownloadPercent(courseId: number): number {
- return downloads.get(courseId)?.percent ?? 0;
- }
-
- async function downloadCourse(course: TheMembersCourse) {
- const status = getCourseDownloadStatus(course.id);
- if (status === "downloading") {
- showToast("info", $t("toast.download_already_active"));
- return;
- }
- if (status === "complete") return;
-
- const appSettings = getSettings();
- let outputDir: string | null = null;
-
- if (appSettings?.download.always_ask_path) {
- outputDir = await open({ directory: true, title: $t("hotmart.choose_folder") }) as string | null;
- if (!outputDir) return;
- } else {
- outputDir = appSettings?.download.default_output_dir ?? null;
- if (!outputDir) {
- outputDir = await open({ directory: true, title: $t("hotmart.choose_folder") }) as string | null;
- if (!outputDir) return;
- }
- }
-
- try {
- await pluginInvoke("courses", "start_themembers_course_download", {
- courseJson: JSON.stringify(course),
- outputDir,
- });
- showToast("info", $t("toast.download_preparing"));
- } catch (e: any) {
- const msg = typeof e === "string" ? e : e.message ?? $t("common.error");
- showToast("error", msg);
- }
- }
-
- let refreshing = $state(false);
-
- async function refreshCourses() {
- refreshing = true;
- loadingCourses = true;
- coursesError = "";
- try {
- courses = await pluginInvoke("courses", "themembers_refresh_courses");
- currentPage = 1;
- } catch (e: any) {
- coursesError = typeof e === "string" ? e : e.message ?? $t('hotmart.courses_error');
- } finally {
- loadingCourses = false;
- refreshing = false;
- }
- }
-</script>
-
-<a href="/courses" class="back-link">
- <svg viewBox="0 0 24 24" width="16" height="16" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
- <path d="M19 12H5" />
- <path d="M12 19l-7-7 7-7" />
- </svg>
- {$t("courses.back")}
-</a>
-
-{#if checking}
- <div class="page-center">
- <span class="spinner"></span>
- <span class="spinner-text">{$t('hotmart.checking_session')}</span>
- </div>
-{:else if loggedIn}
- <div class="page-logged">
- <div class="session-bar">
- <span class="session-info">
- {$t('hotmart.logged_as', { email: sessionEmail || "—" })}
- </span>
- <div class="session-actions">
- <button
- class="button"
- onclick={refreshCourses}
- disabled={refreshing}
- aria-label={$t('hotmart.refresh')}
- >
- <svg viewBox="0 0 24 24" width="14" height="14" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class:spinning={refreshing}>
- <path d="M21 2v6h-6" />
- <path d="M3 12a9 9 0 0115-6.7L21 8" />
- <path d="M3 22v-6h6" />
- <path d="M21 12a9 9 0 01-15 6.7L3 16" />
- </svg>
- </button>
- <button class="button" onclick={handleLogout}>{$t('hotmart.logout')}</button>
- </div>
- </div>
-
- {#if loadingCourses}
- <div class="spinner-section">
- <span class="spinner"></span>
- <span class="spinner-text">{$t('hotmart.loading_courses')}</span>
- </div>
- {:else if coursesError}
- <div class="error-section">
- <p class="error-msg">{coursesError}</p>
- <button class="button" onclick={loadCourses}>{$t('common.retry')}</button>
- </div>
- {:else if courses.length === 0}
- <p class="empty-text">{$t('hotmart.no_courses')}</p>
- {:else}
- <div class="courses-header">
- <h2>{$t('hotmart.courses_title')}</h2>
- <span class="subtext">{courses.length === 1 ? $t('hotmart.course_count_one', { count: courses.length }) : $t('hotmart.course_count', { count: courses.length })}</span>
- </div>
-
- <div class="courses-grid">
- {#each paginatedCourses as course (course.id)}
- <CourseCard
- name={course.name}
- price={""}
- downloadStatus={getCourseDownloadStatus(course.id)}
- downloadPercent={getCourseDownloadPercent(course.id)}
- onDownload={() => downloadCourse(course)}
- />
- {/each}
- </div>
-
- {#if totalPages > 1}
- <div class="pagination">
- <span class="pagination-info">
- {$t('hotmart.page_of', { current: currentPage, total: totalPages })} &middot; {courses.length === 1 ? $t('hotmart.course_count_one', { count: courses.length }) : $t('hotmart.course_count', { count: courses.length })}
- </span>
- <div class="pagination-controls">
- <button
- class="button pagination-btn"
- disabled={currentPage <= 1}
- onclick={() => goToPage(currentPage - 1)}
- >
- &lt;
- </button>
-
- {#each pageNumbers() as page}
- {#if page === -1}
- <span class="pagination-ellipsis">&hellip;</span>
- {:else}
- <button
- class="button pagination-btn"
- class:active={page === currentPage}
- onclick={() => goToPage(page)}
- >
- {page}
- </button>
- {/if}
- {/each}
-
- <button
- class="button pagination-btn"
- disabled={currentPage >= totalPages}
- onclick={() => goToPage(currentPage + 1)}
- >
- &gt;
- </button>
- </div>
- </div>
- {/if}
- {/if}
- </div>
-{:else}
- <div class="page-center">
- <div class="login-card">
- <h2>TheMembers</h2>
-
- <div class="login-tabs">
- <button
- class="button login-tab"
- class:active={loginMode === "credentials"}
- onclick={() => { loginMode = "credentials"; error = ""; }}
- >
- Email & Password
- </button>
- <button
- class="button login-tab"
- class:active={loginMode === "token"}
- onclick={() => { loginMode = "token"; error = ""; }}
- >
- Token
- </button>
- </div>
-
- {#if loginMode === "credentials"}
- <form class="form" onsubmit={(e) => { e.preventDefault(); handleLogin(); }}>
- <label class="field">
- <span class="field-label">{$t('hotmart.email_label')}</span>
- <input
- type="email"
- placeholder={$t('hotmart.email_placeholder')}
- bind:value={email}
- class="input"
- disabled={loading}
- required
- />
- </label>
- <label class="field">
- <span class="field-label">{$t('hotmart.password_label')}</span>
- <input
- type="password"
- placeholder={$t('hotmart.password_placeholder')}
- bind:value={password}
- class="input"
- disabled={loading}
- required
- />
- </label>
- <label class="field">
- <span class="field-label">Domain</span>
- <input
- type="text"
- placeholder="example.themembers.com.br"
- bind:value={domain}
- class="input"
- disabled={loading}
- />
- </label>
-
- {#if error}
- <p class="error-msg">{error}</p>
- {/if}
-
- <button type="submit" class="button" disabled={loading}>
- {#if loading}
- {$t('hotmart.authenticating')}
- {:else}
- {$t('hotmart.login')}
- {/if}
- </button>
- </form>
- {:else}
- <div class="form">
- <label class="field">
- <span class="field-label">Cookies JSON</span>
- <textarea
- class="input token-textarea"
- placeholder="Paste cookies JSON from browser extension or a raw token"
- bind:value={token}
- disabled={loading}
- rows="5"
- ></textarea>
- </label>
-
- <input
- type="file"
- accept=".json,.txt"
- class="hidden-file-input"
- bind:this={fileInput}
- onchange={onFileSelected}
- />
- <button class="button" onclick={() => fileInput?.click()} disabled={loading}>
- Import .json file
- </button>
-
- <label class="field">
- <span class="field-label">Domain</span>
- <input
- type="text"
- placeholder="example.themembers.com.br"
- bind:value={domain}
- class="input"
- disabled={loading}
- />
- </label>
-
- {#if error}
- <p class="error-msg">{error}</p>
- {/if}
-
- <button class="button" onclick={handleTokenLogin} disabled={loading || !token.trim()}>
- {#if loading}
- {$t('hotmart.authenticating')}
- {:else}
- {$t('hotmart.login')}
- {/if}
- </button>
- </div>
- {/if}
- </div>
- </div>
-{/if}
-
-<style>
- .back-link {
- display: inline-flex;
- align-items: center;
- gap: 6px;
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- margin-bottom: var(--padding);
- }
-
- @media (hover: hover) {
- .back-link:hover {
- color: var(--secondary);
- }
- }
-
- .page-center {
- display: flex;
- flex-direction: column;
- align-items: center;
- justify-content: center;
- min-height: calc(100vh - var(--padding) * 4 - 40px);
- gap: var(--padding);
- }
-
- .page-logged {
- display: flex;
- flex-direction: column;
- align-items: center;
- gap: calc(var(--padding) * 1.5);
- padding: calc(var(--padding) * 1.5);
- width: 100%;
- }
-
- .page-logged > :global(*) {
- width: 100%;
- max-width: 1200px;
- }
-
- .session-bar {
- display: flex;
- align-items: center;
- justify-content: space-between;
- }
-
- .session-info {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .session-actions {
- display: flex;
- gap: calc(var(--padding) / 2);
- }
-
- .session-bar :global(.button) {
- padding: calc(var(--padding) / 2) var(--padding);
- font-size: 12.5px;
- }
-
- .spinning {
- animation: spin 0.6s linear infinite;
- }
-
- .courses-header {
- display: flex;
- align-items: baseline;
- gap: var(--padding);
- }
-
- .courses-header h2 {
- margin-block: 0;
- }
-
- .subtext {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .courses-grid {
- display: grid;
- grid-template-columns: repeat(4, 1fr);
- gap: var(--padding);
- }
-
- @media (max-width: 1000px) {
- .courses-grid {
- grid-template-columns: repeat(3, 1fr);
- }
- }
-
- @media (max-width: 750px) {
- .courses-grid {
- grid-template-columns: repeat(2, 1fr);
- }
- }
-
- @media (max-width: 535px) {
- .courses-grid {
- grid-template-columns: 1fr;
- }
- }
-
- .pagination {
- display: flex;
- flex-direction: column;
- align-items: center;
- gap: var(--padding);
- padding-top: var(--padding);
- }
-
- .pagination-info {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .pagination-controls {
- display: flex;
- align-items: center;
- gap: calc(var(--padding) / 3);
- }
-
- .pagination-btn {
- min-width: 36px;
- height: 36px;
- padding: 0;
- display: flex;
- align-items: center;
- justify-content: center;
- font-size: 14.5px;
- }
-
- .pagination-ellipsis {
- min-width: 36px;
- text-align: center;
- color: var(--gray);
- font-size: 14.5px;
- }
-
- .login-card {
- width: 100%;
- max-width: 400px;
- background: var(--button-elevated);
- border-radius: var(--border-radius);
- padding: calc(var(--padding) * 2);
- display: flex;
- flex-direction: column;
- gap: calc(var(--padding) * 1.5);
- }
-
- .login-card h2 {
- margin-block: 0;
- }
-
- .login-tabs {
- display: flex;
- gap: 0;
- }
-
- .login-tab {
- flex: 1;
- border-radius: 0;
- font-size: 12.5px;
- padding: calc(var(--padding) * 0.75) var(--padding);
- }
-
- .login-tab:first-child {
- border-radius: var(--border-radius) 0 0 var(--border-radius);
- }
-
- .login-tab:last-child {
- border-radius: 0 var(--border-radius) var(--border-radius) 0;
- }
-
- .hidden-file-input { display: none; }
-
- .token-textarea {
- resize: vertical;
- min-height: 80px;
- font-size: 11.5px;
- font-family: var(--font-mono);
- line-height: 1.5;
- }
-
- .form {
- display: flex;
- flex-direction: column;
- gap: var(--padding);
- }
-
- .field {
- display: flex;
- flex-direction: column;
- gap: calc(var(--padding) / 2);
- }
-
- .field-label {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .input {
- width: 100%;
- padding: var(--padding);
- font-size: 14.5px;
- background: var(--button);
- border-radius: var(--border-radius);
- color: var(--secondary);
- border: 1px solid var(--input-border);
- }
-
- .input::placeholder {
- color: var(--gray);
- }
-
- .input:focus-visible {
- border-color: var(--secondary);
- outline: none;
- }
-
- .input:disabled {
- opacity: 0.5;
- cursor: default;
- }
-
- .error-msg {
- color: var(--red);
- font-size: 12.5px;
- font-weight: 500;
- }
-
- .spinner-section {
- display: flex;
- flex-direction: column;
- align-items: center;
- gap: var(--padding);
- padding: calc(var(--padding) * 4) 0;
- }
-
- .spinner {
- width: 24px;
- height: 24px;
- border: 2px solid var(--input-border);
- border-top-color: var(--blue);
- border-radius: 50%;
- animation: spin 0.6s linear infinite;
- }
-
- @keyframes spin {
- to {
- transform: rotate(360deg);
- }
- }
-
- .spinner-text {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .error-section {
- display: flex;
- flex-direction: column;
- align-items: center;
- gap: var(--padding);
- padding: calc(var(--padding) * 2) 0;
- }
-
- .empty-text {
- color: var(--gray);
- font-size: 14.5px;
- text-align: center;
- padding: calc(var(--padding) * 4) 0;
- }
-</style>
diff --git a/src/routes/courses/thinkific/+page.svelte b/src/routes/courses/thinkific/+page.svelte
deleted file mode 100644
index a6c7dba0..00000000
--- a/src/routes/courses/thinkific/+page.svelte
+++ /dev/null
@@ -1,624 +0,0 @@
-<script lang="ts">
- import { pluginInvoke } from "$lib/plugin-invoke";
- import { open } from "@tauri-apps/plugin-dialog";
- import CourseCard from "$components/hotmart/CourseCard.svelte";
- import { showToast } from "$lib/stores/toast-store.svelte";
- import { getDownloads } from "$lib/stores/download-store.svelte";
- import { getSettings } from "$lib/stores/settings-store.svelte";
- import { t } from "$lib/i18n";
-
- let downloads = $derived(getDownloads());
-
- type ThinkificCourse = {
- id: string;
- name: string;
- slug: string;
- image_url: string | null;
- };
-
- let cookies = $state("");
- let fileInput: HTMLInputElement = $state() as HTMLInputElement;
- function onFileSelected(e: Event) {
- const input = e.target as HTMLInputElement;
- const file = input.files?.[0];
- if (!file) return;
- const reader = new FileReader();
- reader.onload = () => { cookies = reader.result as string; };
- reader.readAsText(file);
- input.value = "";
- }
- let siteUrl = $state("");
- let loading = $state(false);
- let error = $state("");
-
- let checking = $state(true);
- let loggedIn = $state(false);
- let sessionSiteUrl = $state("");
-
- let courses: ThinkificCourse[] = $state([]);
- let loadingCourses = $state(false);
- let coursesError = $state("");
-
- const ITEMS_PER_PAGE = 12;
- let currentPage = $state(1);
-
- let totalPages = $derived(Math.max(1, Math.ceil(courses.length / ITEMS_PER_PAGE)));
- let paginatedCourses = $derived(
- courses.slice((currentPage - 1) * ITEMS_PER_PAGE, currentPage * ITEMS_PER_PAGE)
- );
-
- let pageNumbers = $derived((): number[] => {
- const pages: number[] = [];
- if (totalPages <= 7) {
- for (let i = 1; i <= totalPages; i++) pages.push(i);
- } else {
- pages.push(1);
- if (currentPage > 3) pages.push(-1);
- const start = Math.max(2, currentPage - 1);
- const end = Math.min(totalPages - 1, currentPage + 1);
- for (let i = start; i <= end; i++) pages.push(i);
- if (currentPage < totalPages - 2) pages.push(-1);
- pages.push(totalPages);
- }
- return pages;
- });
-
- function goToPage(page: number) {
- if (page >= 1 && page <= totalPages) {
- currentPage = page;
- }
- }
-
- $effect(() => {
- checkSession();
- });
-
- async function checkSession() {
- try {
- const result = await pluginInvoke<string>("courses", "thinkific_check_session");
- sessionSiteUrl = result;
- loggedIn = true;
- loadCourses();
- } catch {
- loggedIn = false;
- } finally {
- checking = false;
- }
- }
-
- async function handleLogin() {
- if (!cookies.trim() || !siteUrl.trim()) return;
- error = "";
- loading = true;
- try {
- const result = await pluginInvoke<string>("courses", "thinkific_login", {
- cookies: cookies.trim(),
- siteUrl: siteUrl.trim(),
- });
- sessionSiteUrl = result || siteUrl;
- loggedIn = true;
- loadCourses();
- } catch (e: any) {
- error = typeof e === "string" ? e : e.message ?? $t('hotmart.unknown_error');
- } finally {
- loading = false;
- }
- }
-
- async function handleLogout() {
- try {
- await pluginInvoke("courses", "thinkific_logout");
- } catch {
- }
- loggedIn = false;
- sessionSiteUrl = "";
- courses = [];
- coursesError = "";
- currentPage = 1;
- }
-
- async function loadCourses() {
- loadingCourses = true;
- coursesError = "";
- try {
- courses = await pluginInvoke("courses", "thinkific_list_courses");
- currentPage = 1;
- } catch (e: any) {
- coursesError = typeof e === "string" ? e : e.message ?? $t('hotmart.courses_error');
- } finally {
- loadingCourses = false;
- }
- }
-
- function getCourseDownloadStatus(courseId: string): "idle" | "downloading" | "complete" | "error" {
- const numId = hashCode(courseId);
- const item = downloads.get(numId);
- if (!item) return "idle";
- const s = item.status;
- if (s === "queued" || s === "paused" || s === "seeding") return "downloading";
- return s;
- }
-
- function getCourseDownloadPercent(courseId: string): number {
- const numId = hashCode(courseId);
- return downloads.get(numId)?.percent ?? 0;
- }
-
- function hashCode(str: string): number {
- let hash = 0;
- for (let i = 0; i < str.length; i++) {
- const char = str.charCodeAt(i);
- hash = ((hash << 5) - hash) + char;
- hash |= 0;
- }
- return Math.abs(hash);
- }
-
- async function downloadCourse(course: ThinkificCourse) {
- const status = getCourseDownloadStatus(course.id);
- if (status === "downloading") {
- showToast("info", $t("toast.download_already_active"));
- return;
- }
- if (status === "complete") return;
-
- const appSettings = getSettings();
- let outputDir: string | null = null;
-
- if (appSettings?.download.always_ask_path) {
- outputDir = await open({ directory: true, title: $t("hotmart.choose_folder") }) as string | null;
- if (!outputDir) return;
- } else {
- outputDir = appSettings?.download.default_output_dir ?? null;
- if (!outputDir) {
- outputDir = await open({ directory: true, title: $t("hotmart.choose_folder") }) as string | null;
- if (!outputDir) return;
- }
- }
-
- try {
- await pluginInvoke("courses", "start_thinkific_course_download", {
- courseJson: JSON.stringify(course),
- outputDir,
- });
- showToast("info", $t("toast.download_preparing"));
- } catch (e: any) {
- const msg = typeof e === "string" ? e : e.message ?? $t("common.error");
- showToast("error", msg);
- }
- }
-
- let refreshing = $state(false);
-
- async function refreshCourses() {
- refreshing = true;
- loadingCourses = true;
- coursesError = "";
- try {
- courses = await pluginInvoke("courses", "thinkific_refresh_courses");
- currentPage = 1;
- } catch (e: any) {
- coursesError = typeof e === "string" ? e : e.message ?? $t('hotmart.courses_error');
- } finally {
- loadingCourses = false;
- refreshing = false;
- }
- }
-</script>
-
-<a href="/courses" class="back-link">
- <svg viewBox="0 0 24 24" width="16" height="16" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
- <path d="M19 12H5" />
- <path d="M12 19l-7-7 7-7" />
- </svg>
- {$t("courses.back")}
-</a>
-
-{#if checking}
- <div class="page-center">
- <span class="spinner"></span>
- <span class="spinner-text">{$t('hotmart.checking_session')}</span>
- </div>
-{:else if loggedIn}
- <div class="page-logged">
- <div class="session-bar">
- <span class="session-info">
- {$t('hotmart.logged_as', { email: sessionSiteUrl || "—" })}
- </span>
- <div class="session-actions">
- <button
- class="button"
- onclick={refreshCourses}
- disabled={refreshing}
- aria-label={$t('hotmart.refresh')}
- >
- <svg viewBox="0 0 24 24" width="14" height="14" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class:spinning={refreshing}>
- <path d="M21 2v6h-6" />
- <path d="M3 12a9 9 0 0115-6.7L21 8" />
- <path d="M3 22v-6h6" />
- <path d="M21 12a9 9 0 01-15 6.7L3 16" />
- </svg>
- </button>
- <button class="button" onclick={handleLogout}>{$t('hotmart.logout')}</button>
- </div>
- </div>
-
- {#if loadingCourses}
- <div class="spinner-section">
- <span class="spinner"></span>
- <span class="spinner-text">{$t('hotmart.loading_courses')}</span>
- </div>
- {:else if coursesError}
- <div class="error-section">
- <p class="error-msg">{coursesError}</p>
- <button class="button" onclick={loadCourses}>{$t('common.retry')}</button>
- </div>
- {:else if courses.length === 0}
- <p class="empty-text">{$t('hotmart.no_courses')}</p>
- {:else}
- <div class="courses-header">
- <h2>{$t('hotmart.courses_title')}</h2>
- <span class="subtext">{courses.length === 1 ? $t('hotmart.course_count_one', { count: courses.length }) : $t('hotmart.course_count', { count: courses.length })}</span>
- </div>
-
- <div class="courses-grid">
- {#each paginatedCourses as course (course.id)}
- <CourseCard
- name={course.name}
- price={course.slug}
- imageUrl={course.image_url ?? undefined}
- downloadStatus={getCourseDownloadStatus(course.id)}
- downloadPercent={getCourseDownloadPercent(course.id)}
- onDownload={() => downloadCourse(course)}
- />
- {/each}
- </div>
-
- {#if totalPages > 1}
- <div class="pagination">
- <span class="pagination-info">
- {$t('hotmart.page_of', { current: currentPage, total: totalPages })} &middot; {courses.length === 1 ? $t('hotmart.course_count_one', { count: courses.length }) : $t('hotmart.course_count', { count: courses.length })}
- </span>
- <div class="pagination-controls">
- <button
- class="button pagination-btn"
- disabled={currentPage <= 1}
- onclick={() => goToPage(currentPage - 1)}
- >
- &lt;
- </button>
-
- {#each pageNumbers() as page}
- {#if page === -1}
- <span class="pagination-ellipsis">&hellip;</span>
- {:else}
- <button
- class="button pagination-btn"
- class:active={page === currentPage}
- onclick={() => goToPage(page)}
- >
- {page}
- </button>
- {/if}
- {/each}
-
- <button
- class="button pagination-btn"
- disabled={currentPage >= totalPages}
- onclick={() => goToPage(currentPage + 1)}
- >
- &gt;
- </button>
- </div>
- </div>
- {/if}
- {/if}
- </div>
-{:else}
- <div class="page-center">
- <div class="login-card">
- <h2>Thinkific</h2>
-
- <div class="form">
- <label class="field">
- <span class="field-label">Site URL</span>
- <input
- type="text"
- placeholder="https://yourschool.thinkific.com"
- bind:value={siteUrl}
- class="input"
- disabled={loading}
- required
- />
- </label>
- <label class="field">
- <span class="field-label">Cookies JSON</span>
- <textarea
- class="input token-textarea"
- placeholder="Paste cookies JSON from browser extension or a raw token"
- bind:value={cookies}
- disabled={loading}
- rows="4"
- ></textarea>
- </label>
- <input type="file" accept=".json,.txt" class="hidden-file-input" bind:this={fileInput} onchange={onFileSelected} />
- <button class="button" onclick={() => fileInput?.click()} disabled={loading}>Import .json file</button>
-
- {#if error}
- <p class="error-msg">{error}</p>
- {/if}
-
- <button class="button" onclick={handleLogin} disabled={loading || !cookies.trim() || !siteUrl.trim()}>
- {#if loading}
- {$t('hotmart.authenticating')}
- {:else}
- {$t('hotmart.login')}
- {/if}
- </button>
- </div>
- </div>
- </div>
-{/if}
-
-<style>
- .back-link {
- display: inline-flex;
- align-items: center;
- gap: 6px;
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- margin-bottom: var(--padding);
- }
-
- @media (hover: hover) {
- .back-link:hover {
- color: var(--secondary);
- }
- }
-
- .page-center {
- display: flex;
- flex-direction: column;
- align-items: center;
- justify-content: center;
- min-height: calc(100vh - var(--padding) * 4 - 40px);
- gap: var(--padding);
- }
-
- .page-logged {
- display: flex;
- flex-direction: column;
- align-items: center;
- gap: calc(var(--padding) * 1.5);
- padding: calc(var(--padding) * 1.5);
- width: 100%;
- }
-
- .page-logged > :global(*) {
- width: 100%;
- max-width: 1200px;
- }
-
- .session-bar {
- display: flex;
- align-items: center;
- justify-content: space-between;
- }
-
- .session-info {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .session-actions {
- display: flex;
- gap: calc(var(--padding) / 2);
- }
-
- .session-bar :global(.button) {
- padding: calc(var(--padding) / 2) var(--padding);
- font-size: 12.5px;
- }
-
- .spinning {
- animation: spin 0.6s linear infinite;
- }
-
- .courses-header {
- display: flex;
- align-items: baseline;
- gap: var(--padding);
- }
-
- .courses-header h2 {
- margin-block: 0;
- }
-
- .subtext {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .courses-grid {
- display: grid;
- grid-template-columns: repeat(4, 1fr);
- gap: var(--padding);
- }
-
- @media (max-width: 1000px) {
- .courses-grid {
- grid-template-columns: repeat(3, 1fr);
- }
- }
-
- @media (max-width: 750px) {
- .courses-grid {
- grid-template-columns: repeat(2, 1fr);
- }
- }
-
- @media (max-width: 535px) {
- .courses-grid {
- grid-template-columns: 1fr;
- }
- }
-
- .pagination {
- display: flex;
- flex-direction: column;
- align-items: center;
- gap: var(--padding);
- padding-top: var(--padding);
- }
-
- .pagination-info {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .pagination-controls {
- display: flex;
- align-items: center;
- gap: calc(var(--padding) / 3);
- }
-
- .pagination-btn {
- min-width: 36px;
- height: 36px;
- padding: 0;
- display: flex;
- align-items: center;
- justify-content: center;
- font-size: 14.5px;
- }
-
- .pagination-ellipsis {
- min-width: 36px;
- text-align: center;
- color: var(--gray);
- font-size: 14.5px;
- }
-
- .login-card {
- width: 100%;
- max-width: 400px;
- background: var(--button-elevated);
- border-radius: var(--border-radius);
- padding: calc(var(--padding) * 2);
- display: flex;
- flex-direction: column;
- gap: calc(var(--padding) * 1.5);
- }
-
- .login-card h2 {
- margin-block: 0;
- }
-
- .hidden-file-input {
- display: none;
- }
-
- .token-textarea {
- resize: vertical;
- min-height: 80px;
- font-size: 11.5px;
- font-family: var(--font-mono);
- line-height: 1.5;
- }
-
- .form {
- display: flex;
- flex-direction: column;
- gap: var(--padding);
- }
-
- .field {
- display: flex;
- flex-direction: column;
- gap: calc(var(--padding) / 2);
- }
-
- .field-label {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .input {
- width: 100%;
- padding: var(--padding);
- font-size: 14.5px;
- background: var(--button);
- border-radius: var(--border-radius);
- color: var(--secondary);
- border: 1px solid var(--input-border);
- }
-
- .input::placeholder {
- color: var(--gray);
- }
-
- .input:focus-visible {
- border-color: var(--secondary);
- outline: none;
- }
-
- .input:disabled {
- opacity: 0.5;
- cursor: default;
- }
-
- .error-msg {
- color: var(--red);
- font-size: 12.5px;
- font-weight: 500;
- }
-
- .spinner-section {
- display: flex;
- flex-direction: column;
- align-items: center;
- gap: var(--padding);
- padding: calc(var(--padding) * 4) 0;
- }
-
- .spinner {
- width: 24px;
- height: 24px;
- border: 2px solid var(--input-border);
- border-top-color: var(--blue);
- border-radius: 50%;
- animation: spin 0.6s linear infinite;
- }
-
- @keyframes spin {
- to {
- transform: rotate(360deg);
- }
- }
-
- .spinner-text {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .error-section {
- display: flex;
- flex-direction: column;
- align-items: center;
- gap: var(--padding);
- padding: calc(var(--padding) * 2) 0;
- }
-
- .empty-text {
- color: var(--gray);
- font-size: 14.5px;
- text-align: center;
- padding: calc(var(--padding) * 4) 0;
- }
-</style>
diff --git a/src/routes/courses/udemy/+page.svelte b/src/routes/courses/udemy/+page.svelte
deleted file mode 100644
index a7a23572..00000000
--- a/src/routes/courses/udemy/+page.svelte
+++ /dev/null
@@ -1,760 +0,0 @@
-<script lang="ts">
- import { pluginInvoke } from "$lib/plugin-invoke";
- import { listen } from "@tauri-apps/api/event";
- import { open } from "@tauri-apps/plugin-dialog";
- import CourseCard from "$components/hotmart/CourseCard.svelte";
- import { showToast } from "$lib/stores/toast-store.svelte";
- import { getDownloads } from "$lib/stores/download-store.svelte";
- import { getSettings } from "$lib/stores/settings-store.svelte";
- import { t } from "$lib/i18n";
-
- let downloads = $derived(getDownloads());
-
- type UdemyCourse = {
- id: number;
- title: string;
- published_title: string;
- url: string | null;
- image_url: string | null;
- num_published_lectures: number | null;
- };
-
- let email = $state("");
- let loading = $state(false);
- let error = $state("");
- let waitingCode = $state(false);
-
- let checking = $state(true);
- let loggedIn = $state(false);
- let sessionEmail = $state("");
-
- let loginMode = $state<"email" | "cookies">("email");
- let cookieJson = $state("");
- let portalName = $state("");
-
- let courses: UdemyCourse[] = $state([]);
- let loadingCourses = $state(false);
- let coursesError = $state("");
-
- const ITEMS_PER_PAGE = 12;
- let currentPage = $state(1);
-
- let totalPages = $derived(Math.max(1, Math.ceil(courses.length / ITEMS_PER_PAGE)));
- let paginatedCourses = $derived(
- courses.slice((currentPage - 1) * ITEMS_PER_PAGE, currentPage * ITEMS_PER_PAGE)
- );
-
- let pageNumbers = $derived((): number[] => {
- const pages: number[] = [];
- if (totalPages <= 7) {
- for (let i = 1; i <= totalPages; i++) pages.push(i);
- } else {
- pages.push(1);
- if (currentPage > 3) pages.push(-1);
- const start = Math.max(2, currentPage - 1);
- const end = Math.min(totalPages - 1, currentPage + 1);
- for (let i = start; i <= end; i++) pages.push(i);
- if (currentPage < totalPages - 2) pages.push(-1);
- pages.push(totalPages);
- }
- return pages;
- });
-
- function formatLectures(course: UdemyCourse): string {
- if (course.num_published_lectures === null) return "—";
- return $t('udemy.lectures', { count: course.num_published_lectures });
- }
-
- function goToPage(page: number) {
- if (page >= 1 && page <= totalPages) {
- currentPage = page;
- }
- }
-
- $effect(() => {
- checkSession();
- const unlistenCode = listen("udemy-auth-waiting-code", () => {
- waitingCode = true;
- });
- return () => { unlistenCode.then((fn) => fn()); };
- });
-
- async function checkSession() {
- try {
- const result = await pluginInvoke<string>("courses", "udemy_check_session");
- sessionEmail = result;
- loggedIn = true;
- portalName = await pluginInvoke<string>("courses", "udemy_get_portal");
- loadCourses();
- } catch {
- loggedIn = false;
- } finally {
- checking = false;
- }
- }
-
- async function handleLogin() {
- error = "";
- waitingCode = false;
- loading = true;
- try {
- const result = await pluginInvoke<string>("courses", "udemy_login", { email });
- sessionEmail = result || email;
- loggedIn = true;
- waitingCode = false;
- portalName = "www";
- loadCourses();
- } catch (e: any) {
- error = typeof e === "string" ? e : e.message ?? $t('udemy.unknown_error');
- waitingCode = false;
- } finally {
- loading = false;
- }
- }
-
- async function handleCookieLogin() {
- if (!cookieJson.trim()) return;
- error = "";
- loading = true;
- try {
- const result = await pluginInvoke<string>("courses", "udemy_login_cookies", { cookieJson });
- sessionEmail = result;
- loggedIn = true;
- portalName = await pluginInvoke<string>("courses", "udemy_get_portal");
- loadCourses();
- } catch (e: any) {
- error = typeof e === "string" ? e : e.message ?? $t('udemy.unknown_error');
- } finally {
- loading = false;
- }
- }
-
- let fileInput: HTMLInputElement = $state() as HTMLInputElement;
-
- function loadCookieFile() {
- fileInput.click();
- }
-
- function onFileSelected(e: Event) {
- const input = e.target as HTMLInputElement;
- const file = input.files?.[0];
- if (!file) return;
- const reader = new FileReader();
- reader.onload = () => {
- cookieJson = reader.result as string;
- };
- reader.readAsText(file);
- input.value = "";
- }
-
- async function handleLogout() {
- try {
- await pluginInvoke("courses", "udemy_logout");
- } catch {
- }
- loggedIn = false;
- sessionEmail = "";
- portalName = "";
- courses = [];
- coursesError = "";
- currentPage = 1;
- }
-
- async function loadCourses() {
- loadingCourses = true;
- coursesError = "";
- try {
- courses = await pluginInvoke("courses", "udemy_list_courses");
- currentPage = 1;
- } catch (e: any) {
- coursesError = typeof e === "string" ? e : e.message ?? $t('udemy.courses_error');
- } finally {
- loadingCourses = false;
- }
- }
-
- function getCourseDownloadStatus(courseId: number): "idle" | "downloading" | "complete" | "error" {
- const item = downloads.get(courseId);
- if (!item) return "idle";
- const s = item.status;
- if (s === "queued" || s === "paused" || s === "seeding") return "downloading";
- return s;
- }
-
- function getCourseDownloadPercent(courseId: number): number {
- return downloads.get(courseId)?.percent ?? 0;
- }
-
- async function downloadCourse(course: UdemyCourse) {
- const status = getCourseDownloadStatus(course.id);
- if (status === "downloading") {
- showToast("info", $t("toast.download_already_active"));
- return;
- }
- if (status === "complete") return;
-
- const appSettings = getSettings();
- let outputDir: string | null = null;
-
- if (appSettings?.download.always_ask_path) {
- outputDir = await open({ directory: true, title: $t("udemy.choose_folder") }) as string | null;
- if (!outputDir) return;
- } else {
- outputDir = appSettings?.download.default_output_dir ?? null;
- if (!outputDir) {
- outputDir = await open({ directory: true, title: $t("udemy.choose_folder") }) as string | null;
- if (!outputDir) return;
- }
- }
-
- try {
- await pluginInvoke("courses", "start_udemy_course_download", {
- courseJson: JSON.stringify(course),
- outputDir,
- });
- showToast("info", $t("toast.download_preparing"));
- } catch (e: any) {
- const msg = typeof e === "string" ? e : e.message ?? $t("common.error");
- showToast("error", msg);
- }
- }
-
- let refreshing = $state(false);
-
- async function refreshCourses() {
- refreshing = true;
- loadingCourses = true;
- coursesError = "";
- try {
- courses = await pluginInvoke("courses", "udemy_refresh_courses");
- currentPage = 1;
- } catch (e: any) {
- coursesError = typeof e === "string" ? e : e.message ?? $t('udemy.courses_error');
- } finally {
- loadingCourses = false;
- refreshing = false;
- }
- }
-</script>
-
-<a href="/courses" class="back-link">
- <svg viewBox="0 0 24 24" width="16" height="16" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
- <path d="M19 12H5" />
- <path d="M12 19l-7-7 7-7" />
- </svg>
- {$t("courses.back")}
-</a>
-
-{#if checking}
- <div class="page-center">
- <span class="spinner"></span>
- <span class="spinner-text">{$t('udemy.checking_session')}</span>
- </div>
-{:else if loggedIn}
- <div class="page-logged">
- <div class="session-bar">
- <span class="session-info">
- {#if portalName && portalName !== "www"}
- {$t('udemy.logged_as_enterprise', { email: sessionEmail || "—", portal: portalName })}
- {:else}
- {$t('udemy.logged_as', { email: sessionEmail || "—" })}
- {/if}
- </span>
- <div class="session-actions">
- <button
- class="button"
- onclick={refreshCourses}
- disabled={refreshing}
- aria-label={$t('udemy.refresh')}
- >
- <svg viewBox="0 0 24 24" width="14" height="14" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class:spinning={refreshing}>
- <path d="M21 2v6h-6" />
- <path d="M3 12a9 9 0 0115-6.7L21 8" />
- <path d="M3 22v-6h6" />
- <path d="M21 12a9 9 0 01-15 6.7L3 16" />
- </svg>
- </button>
- <button class="button" onclick={handleLogout}>{$t('udemy.logout')}</button>
- </div>
- </div>
-
- {#if loadingCourses}
- <div class="spinner-section">
- <span class="spinner"></span>
- <span class="spinner-text">{$t('udemy.loading_courses')}</span>
- </div>
- {:else if coursesError}
- <div class="error-section">
- <p class="error-msg">{coursesError}</p>
- <button class="button" onclick={loadCourses}>{$t('common.retry')}</button>
- </div>
- {:else if courses.length === 0}
- <p class="empty-text">{$t('udemy.no_courses')}</p>
- {:else}
- <div class="courses-header">
- <h2>{$t('udemy.courses_title')}</h2>
- <span class="subtext">{courses.length === 1 ? $t('udemy.course_count_one', { count: courses.length }) : $t('udemy.course_count', { count: courses.length })}</span>
- </div>
-
- <div class="courses-grid">
- {#each paginatedCourses as course (course.id)}
- <CourseCard
- name={course.title}
- price={formatLectures(course)}
- imageUrl={course.image_url ?? undefined}
- downloadStatus={getCourseDownloadStatus(course.id)}
- downloadPercent={getCourseDownloadPercent(course.id)}
- onDownload={() => downloadCourse(course)}
- />
- {/each}
- </div>
-
- {#if totalPages > 1}
- <div class="pagination">
- <span class="pagination-info">
- {$t('udemy.page_of', { current: currentPage, total: totalPages })} &middot; {courses.length === 1 ? $t('udemy.course_count_one', { count: courses.length }) : $t('udemy.course_count', { count: courses.length })}
- </span>
- <div class="pagination-controls">
- <button
- class="button pagination-btn"
- disabled={currentPage <= 1}
- onclick={() => goToPage(currentPage - 1)}
- >
- &lt;
- </button>
-
- {#each pageNumbers() as page}
- {#if page === -1}
- <span class="pagination-ellipsis">&hellip;</span>
- {:else}
- <button
- class="button pagination-btn"
- class:active={page === currentPage}
- onclick={() => goToPage(page)}
- >
- {page}
- </button>
- {/if}
- {/each}
-
- <button
- class="button pagination-btn"
- disabled={currentPage >= totalPages}
- onclick={() => goToPage(currentPage + 1)}
- >
- &gt;
- </button>
- </div>
- </div>
- {/if}
- {/if}
- </div>
-{:else}
- <div class="page-center">
- <div class="login-card">
- <h2>{$t('udemy.title')}</h2>
-
- <div class="login-tabs">
- <button
- class="button login-tab"
- class:active={loginMode === "email"}
- onclick={() => { loginMode = "email"; error = ""; }}
- >
- {$t('udemy.login_email_tab')}
- </button>
- <button
- class="button login-tab"
- class:active={loginMode === "cookies"}
- onclick={() => { loginMode = "cookies"; error = ""; }}
- >
- {$t('udemy.login_cookies_tab')}
- </button>
- </div>
-
- {#if loginMode === "email"}
- {#if loading && waitingCode}
- <div class="waiting-code">
- <svg viewBox="0 0 24 24" width="32" height="32" fill="none" stroke="var(--blue)" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round">
- <path d="M3 7a2 2 0 012-2h14a2 2 0 012 2v10a2 2 0 01-2 2H5a2 2 0 01-2-2V7z" />
- <path d="M3 7l9 6 9-6" />
- </svg>
- <h3>{$t('udemy.waiting_code_title')}</h3>
- <p class="waiting-code-text">{$t('udemy.waiting_code')}</p>
- <span class="spinner"></span>
- </div>
- {:else}
- <form class="form" onsubmit={(e) => { e.preventDefault(); handleLogin(); }}>
- <label class="field">
- <span class="field-label">{$t('udemy.email_label')}</span>
- <input
- type="email"
- placeholder={$t('udemy.email_placeholder')}
- bind:value={email}
- class="input"
- disabled={loading}
- required
- />
- </label>
-
- {#if error}
- <p class="error-msg">{error}</p>
- {/if}
-
- <button type="submit" class="button" disabled={loading}>
- {#if loading}
- {$t('udemy.authenticating')}
- {:else}
- {$t('udemy.login')}
- {/if}
- </button>
- </form>
- {/if}
- {:else}
- <div class="form">
- <p class="cookies-instructions">{$t('udemy.cookies_instructions')}</p>
-
- <textarea
- class="input cookies-textarea"
- placeholder={$t('udemy.cookies_placeholder')}
- bind:value={cookieJson}
- disabled={loading}
- rows="6"
- ></textarea>
-
- <input
- type="file"
- accept=".json"
- class="hidden-file-input"
- bind:this={fileInput}
- onchange={onFileSelected}
- />
-
- <button class="button" onclick={loadCookieFile} disabled={loading}>
- {$t('udemy.cookies_load_file')}
- </button>
-
- {#if error}
- <p class="error-msg">{error}</p>
- {/if}
-
- <button class="button" onclick={handleCookieLogin} disabled={loading || !cookieJson.trim()}>
- {#if loading}
- {$t('udemy.authenticating')}
- {:else}
- {$t('udemy.cookies_login')}
- {/if}
- </button>
- </div>
- {/if}
- </div>
- </div>
-{/if}
-
-<style>
- .back-link {
- display: inline-flex;
- align-items: center;
- gap: 6px;
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- margin-bottom: var(--padding);
- }
-
- @media (hover: hover) {
- .back-link:hover {
- color: var(--secondary);
- }
- }
-
- .page-center {
- display: flex;
- flex-direction: column;
- align-items: center;
- justify-content: center;
- min-height: calc(100vh - var(--padding) * 4 - 40px);
- gap: var(--padding);
- }
-
- .page-logged {
- display: flex;
- flex-direction: column;
- align-items: center;
- gap: calc(var(--padding) * 1.5);
- padding: calc(var(--padding) * 1.5);
- width: 100%;
- }
-
- .page-logged > :global(*) {
- width: 100%;
- max-width: 1200px;
- }
-
- .session-bar {
- display: flex;
- align-items: center;
- justify-content: space-between;
- }
-
- .session-info {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .session-actions {
- display: flex;
- gap: calc(var(--padding) / 2);
- }
-
- .session-bar :global(.button) {
- padding: calc(var(--padding) / 2) var(--padding);
- font-size: 12.5px;
- }
-
- .spinning {
- animation: spin 0.6s linear infinite;
- }
-
- .courses-header {
- display: flex;
- align-items: baseline;
- gap: var(--padding);
- }
-
- .courses-header h2 {
- margin-block: 0;
- }
-
- .subtext {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .courses-grid {
- display: grid;
- grid-template-columns: repeat(4, 1fr);
- gap: var(--padding);
- }
-
- @media (max-width: 1000px) {
- .courses-grid {
- grid-template-columns: repeat(3, 1fr);
- }
- }
-
- @media (max-width: 750px) {
- .courses-grid {
- grid-template-columns: repeat(2, 1fr);
- }
- }
-
- @media (max-width: 535px) {
- .courses-grid {
- grid-template-columns: 1fr;
- }
- }
-
- .pagination {
- display: flex;
- flex-direction: column;
- align-items: center;
- gap: var(--padding);
- padding-top: var(--padding);
- }
-
- .pagination-info {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .pagination-controls {
- display: flex;
- align-items: center;
- gap: calc(var(--padding) / 3);
- }
-
- .pagination-btn {
- min-width: 36px;
- height: 36px;
- padding: 0;
- display: flex;
- align-items: center;
- justify-content: center;
- font-size: 14.5px;
- }
-
- .pagination-ellipsis {
- min-width: 36px;
- text-align: center;
- color: var(--gray);
- font-size: 14.5px;
- }
-
- .login-card {
- width: 100%;
- max-width: 400px;
- background: var(--button-elevated);
- border-radius: var(--border-radius);
- padding: calc(var(--padding) * 2);
- display: flex;
- flex-direction: column;
- gap: calc(var(--padding) * 1.5);
- }
-
- .login-card h2 {
- margin-block: 0;
- }
-
- .login-tabs {
- display: flex;
- gap: 0;
- }
-
- .login-tab {
- flex: 1;
- border-radius: 0;
- font-size: 12.5px;
- padding: calc(var(--padding) * 0.75) var(--padding);
- }
-
- .login-tab:first-child {
- border-radius: var(--border-radius) 0 0 var(--border-radius);
- }
-
- .login-tab:last-child {
- border-radius: 0 var(--border-radius) var(--border-radius) 0;
- }
-
- .cookies-instructions {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- line-height: 1.6;
- }
-
- .cookies-textarea {
- resize: vertical;
- min-height: 100px;
- font-size: 12px;
- line-height: 1.5;
- }
-
- .hidden-file-input {
- display: none;
- }
-
- .form {
- display: flex;
- flex-direction: column;
- gap: var(--padding);
- }
-
- .field {
- display: flex;
- flex-direction: column;
- gap: calc(var(--padding) / 2);
- }
-
- .field-label {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .input {
- width: 100%;
- padding: var(--padding);
- font-size: 14.5px;
- background: var(--button);
- border-radius: var(--border-radius);
- color: var(--secondary);
- border: 1px solid var(--input-border);
- }
-
- .input::placeholder {
- color: var(--gray);
- }
-
- .input:focus-visible {
- border-color: var(--secondary);
- outline: none;
- }
-
- .input:disabled {
- opacity: 0.5;
- cursor: default;
- }
-
- .error-msg {
- color: var(--red);
- font-size: 12.5px;
- font-weight: 500;
- }
-
- .waiting-code {
- display: flex;
- flex-direction: column;
- align-items: center;
- gap: var(--padding);
- padding: var(--padding) 0;
- text-align: center;
- }
-
- .waiting-code h3 {
- margin-block: 0;
- }
-
- .waiting-code-text {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- line-height: 1.6;
- }
-
- .spinner-section {
- display: flex;
- flex-direction: column;
- align-items: center;
- gap: var(--padding);
- padding: calc(var(--padding) * 4) 0;
- }
-
- .spinner {
- width: 24px;
- height: 24px;
- border: 2px solid var(--input-border);
- border-top-color: var(--blue);
- border-radius: 50%;
- animation: spin 0.6s linear infinite;
- }
-
- @keyframes spin {
- to {
- transform: rotate(360deg);
- }
- }
-
- .spinner-text {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .error-section {
- display: flex;
- flex-direction: column;
- align-items: center;
- gap: var(--padding);
- padding: calc(var(--padding) * 2) 0;
- }
-
- .empty-text {
- color: var(--gray);
- font-size: 14.5px;
- text-align: center;
- padding: calc(var(--padding) * 4) 0;
- }
-</style>
diff --git a/src/routes/courses/voompplay/+page.svelte b/src/routes/courses/voompplay/+page.svelte
deleted file mode 100644
index 621aafb3..00000000
--- a/src/routes/courses/voompplay/+page.svelte
+++ /dev/null
@@ -1,606 +0,0 @@
-<script lang="ts">
- import { pluginInvoke } from "$lib/plugin-invoke";
- import { open } from "@tauri-apps/plugin-dialog";
- import CourseCard from "$components/hotmart/CourseCard.svelte";
- import { showToast } from "$lib/stores/toast-store.svelte";
- import { getDownloads } from "$lib/stores/download-store.svelte";
- import { getSettings } from "$lib/stores/settings-store.svelte";
- import { t } from "$lib/i18n";
-
- let downloads = $derived(getDownloads());
-
- type VoompCourse = {
- id: number;
- name: string;
- lessons_count: number;
- };
-
- let token = $state("");
- let loading = $state(false);
- let error = $state("");
-
- let fileInput: HTMLInputElement = $state() as HTMLInputElement;
-
- function onFileSelected(e: Event) {
- const input = e.target as HTMLInputElement;
- const file = input.files?.[0];
- if (!file) return;
- const reader = new FileReader();
- reader.onload = () => { token = reader.result as string; };
- reader.readAsText(file);
- input.value = "";
- }
-
- let checking = $state(true);
- let loggedIn = $state(false);
- let sessionEmail = $state("");
-
- let courses: VoompCourse[] = $state([]);
- let loadingCourses = $state(false);
- let coursesError = $state("");
-
- const ITEMS_PER_PAGE = 12;
- let currentPage = $state(1);
-
- let totalPages = $derived(Math.max(1, Math.ceil(courses.length / ITEMS_PER_PAGE)));
- let paginatedCourses = $derived(
- courses.slice((currentPage - 1) * ITEMS_PER_PAGE, currentPage * ITEMS_PER_PAGE)
- );
-
- let pageNumbers = $derived((): number[] => {
- const pages: number[] = [];
- if (totalPages <= 7) {
- for (let i = 1; i <= totalPages; i++) pages.push(i);
- } else {
- pages.push(1);
- if (currentPage > 3) pages.push(-1);
- const start = Math.max(2, currentPage - 1);
- const end = Math.min(totalPages - 1, currentPage + 1);
- for (let i = start; i <= end; i++) pages.push(i);
- if (currentPage < totalPages - 2) pages.push(-1);
- pages.push(totalPages);
- }
- return pages;
- });
-
- function goToPage(page: number) {
- if (page >= 1 && page <= totalPages) {
- currentPage = page;
- }
- }
-
- $effect(() => {
- checkSession();
- });
-
- async function checkSession() {
- try {
- const result = await pluginInvoke<string>("courses", "voomp_check_session");
- sessionEmail = result;
- loggedIn = true;
- loadCourses();
- } catch {
- loggedIn = false;
- } finally {
- checking = false;
- }
- }
-
- async function handleTokenLogin() {
- if (!token.trim()) return;
- error = "";
- loading = true;
- try {
- const result = await pluginInvoke<string>("courses", "voomp_login_token", { token: token.trim() });
- sessionEmail = result || "Token";
- loggedIn = true;
- loadCourses();
- } catch (e: any) {
- error = typeof e === "string" ? e : e.message ?? $t('hotmart.unknown_error');
- } finally {
- loading = false;
- }
- }
-
- async function handleLogout() {
- try {
- await pluginInvoke("courses", "voomp_logout");
- } catch {
- }
- loggedIn = false;
- sessionEmail = "";
- courses = [];
- coursesError = "";
- currentPage = 1;
- }
-
- async function loadCourses() {
- loadingCourses = true;
- coursesError = "";
- try {
- courses = await pluginInvoke("courses", "voomp_list_courses");
- currentPage = 1;
- } catch (e: any) {
- coursesError = typeof e === "string" ? e : e.message ?? $t('hotmart.courses_error');
- } finally {
- loadingCourses = false;
- }
- }
-
- function getCourseDownloadStatus(courseId: number): "idle" | "downloading" | "complete" | "error" {
- const item = downloads.get(courseId);
- if (!item) return "idle";
- const s = item.status;
- if (s === "queued" || s === "paused" || s === "seeding") return "downloading";
- return s;
- }
-
- function getCourseDownloadPercent(courseId: number): number {
- return downloads.get(courseId)?.percent ?? 0;
- }
-
- async function downloadCourse(course: VoompCourse) {
- const status = getCourseDownloadStatus(course.id);
- if (status === "downloading") {
- showToast("info", $t("toast.download_already_active"));
- return;
- }
- if (status === "complete") return;
-
- const appSettings = getSettings();
- let outputDir: string | null = null;
-
- if (appSettings?.download.always_ask_path) {
- outputDir = await open({ directory: true, title: $t("hotmart.choose_folder") }) as string | null;
- if (!outputDir) return;
- } else {
- outputDir = appSettings?.download.default_output_dir ?? null;
- if (!outputDir) {
- outputDir = await open({ directory: true, title: $t("hotmart.choose_folder") }) as string | null;
- if (!outputDir) return;
- }
- }
-
- try {
- await pluginInvoke("courses", "start_voomp_course_download", {
- courseJson: JSON.stringify(course),
- outputDir,
- });
- showToast("info", $t("toast.download_preparing"));
- } catch (e: any) {
- const msg = typeof e === "string" ? e : e.message ?? $t("common.error");
- showToast("error", msg);
- }
- }
-
- let refreshing = $state(false);
-
- async function refreshCourses() {
- refreshing = true;
- loadingCourses = true;
- coursesError = "";
- try {
- courses = await pluginInvoke("courses", "voomp_refresh_courses");
- currentPage = 1;
- } catch (e: any) {
- coursesError = typeof e === "string" ? e : e.message ?? $t('hotmart.courses_error');
- } finally {
- loadingCourses = false;
- refreshing = false;
- }
- }
-</script>
-
-<a href="/courses" class="back-link">
- <svg viewBox="0 0 24 24" width="16" height="16" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
- <path d="M19 12H5" />
- <path d="M12 19l-7-7 7-7" />
- </svg>
- {$t("courses.back")}
-</a>
-
-{#if checking}
- <div class="page-center">
- <span class="spinner"></span>
- <span class="spinner-text">{$t('hotmart.checking_session')}</span>
- </div>
-{:else if loggedIn}
- <div class="page-logged">
- <div class="session-bar">
- <span class="session-info">
- {$t('hotmart.logged_as', { email: sessionEmail || "\u2014" })}
- </span>
- <div class="session-actions">
- <button
- class="button"
- onclick={refreshCourses}
- disabled={refreshing}
- aria-label={$t('hotmart.refresh')}
- >
- <svg viewBox="0 0 24 24" width="14" height="14" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class:spinning={refreshing}>
- <path d="M21 2v6h-6" />
- <path d="M3 12a9 9 0 0115-6.7L21 8" />
- <path d="M3 22v-6h6" />
- <path d="M21 12a9 9 0 01-15 6.7L3 16" />
- </svg>
- </button>
- <button class="button" onclick={handleLogout}>{$t('hotmart.logout')}</button>
- </div>
- </div>
-
- {#if loadingCourses}
- <div class="spinner-section">
- <span class="spinner"></span>
- <span class="spinner-text">{$t('hotmart.loading_courses')}</span>
- </div>
- {:else if coursesError}
- <div class="error-section">
- <p class="error-msg">{coursesError}</p>
- <button class="button" onclick={loadCourses}>{$t('common.retry')}</button>
- </div>
- {:else if courses.length === 0}
- <p class="empty-text">{$t('hotmart.no_courses')}</p>
- {:else}
- <div class="courses-header">
- <h2>{$t('hotmart.courses_title')}</h2>
- <span class="subtext">{courses.length === 1 ? $t('hotmart.course_count_one', { count: courses.length }) : $t('hotmart.course_count', { count: courses.length })}</span>
- </div>
-
- <div class="courses-grid">
- {#each paginatedCourses as course (course.id)}
- <CourseCard
- name={course.name}
- price={course.lessons_count === 1 ? "1 lesson" : `${course.lessons_count} lessons`}
- downloadStatus={getCourseDownloadStatus(course.id)}
- downloadPercent={getCourseDownloadPercent(course.id)}
- onDownload={() => downloadCourse(course)}
- />
- {/each}
- </div>
-
- {#if totalPages > 1}
- <div class="pagination">
- <span class="pagination-info">
- {$t('hotmart.page_of', { current: currentPage, total: totalPages })} &middot; {courses.length === 1 ? $t('hotmart.course_count_one', { count: courses.length }) : $t('hotmart.course_count', { count: courses.length })}
- </span>
- <div class="pagination-controls">
- <button
- class="button pagination-btn"
- disabled={currentPage <= 1}
- onclick={() => goToPage(currentPage - 1)}
- >
- &lt;
- </button>
-
- {#each pageNumbers() as page}
- {#if page === -1}
- <span class="pagination-ellipsis">&hellip;</span>
- {:else}
- <button
- class="button pagination-btn"
- class:active={page === currentPage}
- onclick={() => goToPage(page)}
- >
- {page}
- </button>
- {/if}
- {/each}
-
- <button
- class="button pagination-btn"
- disabled={currentPage >= totalPages}
- onclick={() => goToPage(currentPage + 1)}
- >
- &gt;
- </button>
- </div>
- </div>
- {/if}
- {/if}
- </div>
-{:else}
- <div class="page-center">
- <div class="login-card">
- <h2>Voomp Play</h2>
-
- <div class="form">
- <label class="field">
- <span class="field-label">Cookies JSON</span>
- <textarea
- class="input token-textarea"
- placeholder="Paste cookies JSON from browser extension or a raw token"
- bind:value={token}
- disabled={loading}
- rows="5"
- ></textarea>
- </label>
-
- <input
- type="file"
- accept=".json,.txt"
- class="hidden-file-input"
- bind:this={fileInput}
- onchange={onFileSelected}
- />
- <button class="button" onclick={() => fileInput?.click()} disabled={loading}>
- Import .json file
- </button>
-
- {#if error}
- <p class="error-msg">{error}</p>
- {/if}
-
- <button class="button" onclick={handleTokenLogin} disabled={loading || !token.trim()}>
- {#if loading}
- {$t('hotmart.authenticating')}
- {:else}
- {$t('hotmart.login')}
- {/if}
- </button>
- </div>
- </div>
- </div>
-{/if}
-
-<style>
- .back-link {
- display: inline-flex;
- align-items: center;
- gap: 6px;
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- margin-bottom: var(--padding);
- }
-
- @media (hover: hover) {
- .back-link:hover {
- color: var(--secondary);
- }
- }
-
- .page-center {
- display: flex;
- flex-direction: column;
- align-items: center;
- justify-content: center;
- min-height: calc(100vh - var(--padding) * 4 - 40px);
- gap: var(--padding);
- }
-
- .page-logged {
- display: flex;
- flex-direction: column;
- align-items: center;
- gap: calc(var(--padding) * 1.5);
- padding: calc(var(--padding) * 1.5);
- width: 100%;
- }
-
- .page-logged > :global(*) {
- width: 100%;
- max-width: 1200px;
- }
-
- .session-bar {
- display: flex;
- align-items: center;
- justify-content: space-between;
- }
-
- .session-info {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .session-actions {
- display: flex;
- gap: calc(var(--padding) / 2);
- }
-
- .session-bar :global(.button) {
- padding: calc(var(--padding) / 2) var(--padding);
- font-size: 12.5px;
- }
-
- .spinning {
- animation: spin 0.6s linear infinite;
- }
-
- .courses-header {
- display: flex;
- align-items: baseline;
- gap: var(--padding);
- }
-
- .courses-header h2 {
- margin-block: 0;
- }
-
- .subtext {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .courses-grid {
- display: grid;
- grid-template-columns: repeat(4, 1fr);
- gap: var(--padding);
- }
-
- @media (max-width: 1000px) {
- .courses-grid {
- grid-template-columns: repeat(3, 1fr);
- }
- }
-
- @media (max-width: 750px) {
- .courses-grid {
- grid-template-columns: repeat(2, 1fr);
- }
- }
-
- @media (max-width: 535px) {
- .courses-grid {
- grid-template-columns: 1fr;
- }
- }
-
- .pagination {
- display: flex;
- flex-direction: column;
- align-items: center;
- gap: var(--padding);
- padding-top: var(--padding);
- }
-
- .pagination-info {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .pagination-controls {
- display: flex;
- align-items: center;
- gap: calc(var(--padding) / 3);
- }
-
- .pagination-btn {
- min-width: 36px;
- height: 36px;
- padding: 0;
- display: flex;
- align-items: center;
- justify-content: center;
- font-size: 14.5px;
- }
-
- .pagination-ellipsis {
- min-width: 36px;
- text-align: center;
- color: var(--gray);
- font-size: 14.5px;
- }
-
- .login-card {
- width: 100%;
- max-width: 400px;
- background: var(--button-elevated);
- border-radius: var(--border-radius);
- padding: calc(var(--padding) * 2);
- display: flex;
- flex-direction: column;
- gap: calc(var(--padding) * 1.5);
- }
-
- .login-card h2 {
- margin-block: 0;
- }
-
- .hidden-file-input {
- display: none;
- }
-
- .token-textarea {
- resize: vertical;
- min-height: 80px;
- font-size: 11.5px;
- font-family: var(--font-mono);
- line-height: 1.5;
- }
-
- .form {
- display: flex;
- flex-direction: column;
- gap: var(--padding);
- }
-
- .field {
- display: flex;
- flex-direction: column;
- gap: calc(var(--padding) / 2);
- }
-
- .field-label {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .input {
- width: 100%;
- padding: var(--padding);
- font-size: 14.5px;
- background: var(--button);
- border-radius: var(--border-radius);
- color: var(--secondary);
- border: 1px solid var(--input-border);
- }
-
- .input::placeholder {
- color: var(--gray);
- }
-
- .input:focus-visible {
- border-color: var(--secondary);
- outline: none;
- }
-
- .input:disabled {
- opacity: 0.5;
- cursor: default;
- }
-
- .error-msg {
- color: var(--red);
- font-size: 12.5px;
- font-weight: 500;
- }
-
- .spinner-section {
- display: flex;
- flex-direction: column;
- align-items: center;
- gap: var(--padding);
- padding: calc(var(--padding) * 4) 0;
- }
-
- .spinner {
- width: 24px;
- height: 24px;
- border: 2px solid var(--input-border);
- border-top-color: var(--blue);
- border-radius: 50%;
- animation: spin 0.6s linear infinite;
- }
-
- @keyframes spin {
- to {
- transform: rotate(360deg);
- }
- }
-
- .spinner-text {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .error-section {
- display: flex;
- flex-direction: column;
- align-items: center;
- gap: var(--padding);
- padding: calc(var(--padding) * 2) 0;
- }
-
- .empty-text {
- color: var(--gray);
- font-size: 14.5px;
- text-align: center;
- padding: calc(var(--padding) * 4) 0;
- }
-</style>