inital commit
This commit is contained in:
3
src/app.css
Normal file
3
src/app.css
Normal file
@ -0,0 +1,3 @@
|
||||
@tailwind base;
|
||||
@tailwind components;
|
||||
@tailwind utilities;
|
13
src/app.d.ts
vendored
Normal file
13
src/app.d.ts
vendored
Normal file
@ -0,0 +1,13 @@
|
||||
// See https://kit.svelte.dev/docs/types#app
|
||||
// for information about these interfaces
|
||||
declare global {
|
||||
namespace App {
|
||||
// interface Error {}
|
||||
// interface Locals {}
|
||||
// interface PageData {}
|
||||
// interface PageState {}
|
||||
// interface Platform {}
|
||||
}
|
||||
}
|
||||
|
||||
export {};
|
12
src/app.html
Normal file
12
src/app.html
Normal file
@ -0,0 +1,12 @@
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<link rel="icon" href="%sveltekit.assets%/favicon.png" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||
%sveltekit.head%
|
||||
</head>
|
||||
<body data-sveltekit-preload-data="hover">
|
||||
<div style="display: contents">%sveltekit.body%</div>
|
||||
</body>
|
||||
</html>
|
1
src/lib/index.ts
Normal file
1
src/lib/index.ts
Normal file
@ -0,0 +1 @@
|
||||
// place files you want to import through the `$lib` alias in this folder.
|
255
src/lib/types.ts
Normal file
255
src/lib/types.ts
Normal file
@ -0,0 +1,255 @@
|
||||
export type Config = {
|
||||
version: number;
|
||||
is_first_run: boolean;
|
||||
fansly_token: string;
|
||||
sync_interval: number;
|
||||
last_sync: number;
|
||||
last_sync_data: SyncData;
|
||||
};
|
||||
|
||||
export interface SyncData {
|
||||
followers: Follower[];
|
||||
subscribers: Subscriber[];
|
||||
}
|
||||
|
||||
interface Subscriber {
|
||||
id: string;
|
||||
historyId: string;
|
||||
subscriberId: string;
|
||||
subscriptionTierId: string;
|
||||
subscriptionTierName: string;
|
||||
subscriptionTierColor: string;
|
||||
planId: string;
|
||||
promoId: null | string;
|
||||
giftCodeId: null | string;
|
||||
paymentMethodId: string;
|
||||
status: number;
|
||||
price: number;
|
||||
renewPrice: number;
|
||||
renewCorrelationId: string;
|
||||
autoRenew: number;
|
||||
billingCycle: number;
|
||||
duration: number;
|
||||
renewDate: number;
|
||||
version: number;
|
||||
createdAt: number;
|
||||
updatedAt: number;
|
||||
endsAt: number;
|
||||
promoPrice: null | number;
|
||||
promoDuration: null | number;
|
||||
promoStatus: null | number;
|
||||
promoStartsAt: null | number;
|
||||
promoEndsAt: null | number;
|
||||
}
|
||||
|
||||
interface Follower {
|
||||
followerId: string;
|
||||
}
|
||||
|
||||
export interface AccountInfoResponse {
|
||||
success: boolean;
|
||||
response: AccountInfo[];
|
||||
}
|
||||
|
||||
export interface AccountInfo {
|
||||
id: string;
|
||||
username: string;
|
||||
displayName: string;
|
||||
flags: number;
|
||||
version: number;
|
||||
createdAt: number;
|
||||
followCount: number;
|
||||
subscriberCount: number;
|
||||
permissions: Permissions;
|
||||
profileAccessFlags: number;
|
||||
profileFlags: number;
|
||||
about: string;
|
||||
location: string;
|
||||
profileSocials: ProfileSocial[];
|
||||
pinnedPosts: PinnedPost[];
|
||||
walls: Wall[];
|
||||
timelineStats: TimelineStats;
|
||||
statusId: number;
|
||||
lastSeenAt: number;
|
||||
mediaStoryState: MediaStoryState;
|
||||
accountMediaLikes: number;
|
||||
avatar: Avatar;
|
||||
banner: Avatar;
|
||||
postLikes: number;
|
||||
streaming: Streaming;
|
||||
subscriptionTiers: SubscriptionTier[];
|
||||
profileAccess: boolean;
|
||||
}
|
||||
|
||||
export interface SubscriptionTier {
|
||||
id: string;
|
||||
accountId: string;
|
||||
name: string;
|
||||
color: string;
|
||||
pos: number;
|
||||
price: number;
|
||||
maxSubscribers: number;
|
||||
subscriptionBenefits: string[];
|
||||
includedTierIds: string[];
|
||||
plans: Plan[];
|
||||
}
|
||||
|
||||
interface Plan {
|
||||
id: string;
|
||||
status: number;
|
||||
billingCycle: number;
|
||||
price: number;
|
||||
useAmounts: number;
|
||||
promos: Promo[];
|
||||
uses: number;
|
||||
}
|
||||
|
||||
interface Promo {
|
||||
id: string;
|
||||
status: number;
|
||||
price: number;
|
||||
duration: number;
|
||||
maxUses: number;
|
||||
maxUsesBefore?: unknown;
|
||||
newSubscribersOnly: number;
|
||||
startsAt: number;
|
||||
endsAt: number;
|
||||
uses: number;
|
||||
}
|
||||
|
||||
interface Streaming {
|
||||
accountId: string;
|
||||
channel: Channel;
|
||||
enabled: boolean;
|
||||
}
|
||||
|
||||
interface Channel {
|
||||
id: string;
|
||||
accountId: string;
|
||||
playbackUrl: string;
|
||||
chatRoomId: string;
|
||||
status: number;
|
||||
version: number;
|
||||
createdAt: number;
|
||||
updatedAt?: unknown;
|
||||
stream: Stream;
|
||||
arn?: unknown;
|
||||
ingestEndpoint?: unknown;
|
||||
}
|
||||
|
||||
interface Stream {
|
||||
id: string;
|
||||
historyId: string;
|
||||
channelId: string;
|
||||
accountId: string;
|
||||
title: string;
|
||||
status: number;
|
||||
viewerCount: number;
|
||||
version: number;
|
||||
createdAt: number;
|
||||
updatedAt?: unknown;
|
||||
lastFetchedAt: number;
|
||||
startedAt: number;
|
||||
permissions: Permissions2;
|
||||
}
|
||||
|
||||
interface Permissions2 {
|
||||
permissionFlags: PermissionFlag[];
|
||||
}
|
||||
|
||||
interface PermissionFlag {
|
||||
id: string;
|
||||
streamId: string;
|
||||
type: number;
|
||||
flags: number;
|
||||
price: number;
|
||||
metadata: string;
|
||||
}
|
||||
|
||||
interface Avatar {
|
||||
id: string;
|
||||
type: number;
|
||||
status: number;
|
||||
accountId: string;
|
||||
mimetype: string;
|
||||
flags: number;
|
||||
location: string;
|
||||
width: number;
|
||||
height: number;
|
||||
metadata: string;
|
||||
updatedAt: number;
|
||||
createdAt: number;
|
||||
variants: Variant[];
|
||||
variantHash: VariantHash;
|
||||
locations: Location[];
|
||||
}
|
||||
|
||||
type VariantHash = unknown;
|
||||
|
||||
interface Variant {
|
||||
id: string;
|
||||
type: number;
|
||||
status: number;
|
||||
mimetype: string;
|
||||
flags: number;
|
||||
location: string;
|
||||
width: number;
|
||||
height: number;
|
||||
metadata: string;
|
||||
updatedAt: number;
|
||||
locations: Location[];
|
||||
}
|
||||
|
||||
interface Location {
|
||||
locationId: string;
|
||||
location: string;
|
||||
}
|
||||
|
||||
interface MediaStoryState {
|
||||
accountId: string;
|
||||
status: number;
|
||||
storyCount: number;
|
||||
version: number;
|
||||
createdAt: number;
|
||||
updatedAt: number;
|
||||
hasActiveStories: boolean;
|
||||
}
|
||||
|
||||
interface TimelineStats {
|
||||
accountId: string;
|
||||
imageCount: number;
|
||||
videoCount: number;
|
||||
bundleCount: number;
|
||||
bundleImageCount: number;
|
||||
bundleVideoCount: number;
|
||||
fetchedAt: number;
|
||||
}
|
||||
|
||||
interface Wall {
|
||||
id: string;
|
||||
accountId: string;
|
||||
pos: number;
|
||||
name: string;
|
||||
description: string;
|
||||
metadata: string;
|
||||
}
|
||||
|
||||
interface PinnedPost {
|
||||
postId: string;
|
||||
accountId: string;
|
||||
pos: number;
|
||||
createdAt: number;
|
||||
}
|
||||
|
||||
interface ProfileSocial {
|
||||
providerId: string;
|
||||
handle: string;
|
||||
}
|
||||
|
||||
interface Permissions {
|
||||
accountPermissionFlags: AccountPermissionFlags;
|
||||
}
|
||||
|
||||
interface AccountPermissionFlags {
|
||||
flags: number;
|
||||
}
|
9
src/lib/utils.ts
Normal file
9
src/lib/utils.ts
Normal file
@ -0,0 +1,9 @@
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
export const awaiter = async <T>(promise: Promise<T>): Promise<[T | null, any | null]> => {
|
||||
try {
|
||||
const data: T = await promise;
|
||||
return [data, null];
|
||||
} catch (err) {
|
||||
return [null, err];
|
||||
}
|
||||
};
|
5
src/routes/+layout.svelte
Normal file
5
src/routes/+layout.svelte
Normal file
@ -0,0 +1,5 @@
|
||||
<script>
|
||||
import '../app.css';
|
||||
</script>
|
||||
|
||||
<slot />
|
2
src/routes/+layout.ts
Normal file
2
src/routes/+layout.ts
Normal file
@ -0,0 +1,2 @@
|
||||
export const prerender = true;
|
||||
export const ssr = false;
|
98
src/routes/+page.svelte
Normal file
98
src/routes/+page.svelte
Normal file
@ -0,0 +1,98 @@
|
||||
<script lang="ts">
|
||||
let status = 'Initializing...';
|
||||
import { invoke } from '@tauri-apps/api/tauri';
|
||||
import { dialog, clipboard } from '@tauri-apps/api';
|
||||
import { awaiter } from '$lib/utils';
|
||||
import { onMount } from 'svelte';
|
||||
import type { Config } from '$lib/types';
|
||||
import { isPermissionGranted, requestPermission } from '@tauri-apps/api/notification';
|
||||
|
||||
onMount(async () => {
|
||||
const [_, configInitError] = await awaiter(invoke('init_config'));
|
||||
|
||||
if (configInitError) {
|
||||
status = 'Failed to initialize configuration';
|
||||
await dialog.message(
|
||||
`Something went wrong while initializing the configuration. We've copied the error to your clipboard. Please contact us.\n\nError: ${configInitError}\n\nThe application will now close.`,
|
||||
{ title: 'FanslySync | Initialization Error', type: 'error' }
|
||||
);
|
||||
|
||||
await clipboard.writeText(configInitError);
|
||||
invoke('quit', { code: 1 });
|
||||
return;
|
||||
}
|
||||
|
||||
const [config, configError] = await awaiter(invoke('get_config') as Promise<Config>);
|
||||
|
||||
if (configError || !config || config === null) {
|
||||
status = 'Failed to get configuration';
|
||||
await dialog.message(
|
||||
`Something went wrong while getting the configuration. We've copied the error to your clipboard. Please contact us.\n\nError: ${configError ?? 'Config was null'}\n\nThe application will now close.`,
|
||||
{ title: 'FanslySync | Configuration Error', type: 'error' }
|
||||
);
|
||||
|
||||
await clipboard.writeText(configError);
|
||||
invoke('quit', { code: 1 });
|
||||
return;
|
||||
}
|
||||
|
||||
const permissionGranted = await isPermissionGranted();
|
||||
if (!permissionGranted) {
|
||||
let result = await requestPermission();
|
||||
if (result !== 'granted') {
|
||||
status = 'Notification permission denied';
|
||||
await dialog.message(
|
||||
`FanslySync requires notification permissions to function properly. Please enable notifications and restart the application.`,
|
||||
{ title: 'FanslySync | Notification Permission Error', type: 'error' }
|
||||
);
|
||||
|
||||
invoke('quit', { code: 1 });
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
status = 'Initialization complete!';
|
||||
// Wait 1000ms before redirecting to /setup or /home
|
||||
await new Promise((resolve) => setTimeout(resolve, 1000));
|
||||
|
||||
if (config.is_first_run) {
|
||||
// Navigate to /setup
|
||||
window.location.href = '/setup';
|
||||
} else {
|
||||
// todo: set jwt for future requests
|
||||
await invoke('fansly_set_token', { token: config.fansly_token });
|
||||
window.location.href = '/home';
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
||||
<div class="container bg-zinc-800 w-screen h-screen">
|
||||
<!-- Centered loading spinner -->
|
||||
<div class="flex flex-col justify-center items-center h-screen">
|
||||
<img src="/fanslySync.png" alt="FanslySync Logo" class="w-24 h-24" />
|
||||
<h1 class="text-2xl font-bold mt-2 text-white">FanslySync</h1>
|
||||
<p class="text-gray-400 mb-3">
|
||||
{status}
|
||||
</p>
|
||||
|
||||
<div role="status">
|
||||
<svg
|
||||
aria-hidden="true"
|
||||
class="w-14 h-14 text-gray-200 animate-spin dark:text-gray-600 fill-[#209CEE]"
|
||||
viewBox="0 0 100 101"
|
||||
fill="none"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
>
|
||||
<path
|
||||
d="M100 50.5908C100 78.2051 77.6142 100.591 50 100.591C22.3858 100.591 0 78.2051 0 50.5908C0 22.9766 22.3858 0.59082 50 0.59082C77.6142 0.59082 100 22.9766 100 50.5908ZM9.08144 50.5908C9.08144 73.1895 27.4013 91.5094 50 91.5094C72.5987 91.5094 90.9186 73.1895 90.9186 50.5908C90.9186 27.9921 72.5987 9.67226 50 9.67226C27.4013 9.67226 9.08144 27.9921 9.08144 50.5908Z"
|
||||
fill="currentColor"
|
||||
/>
|
||||
<path
|
||||
d="M93.9676 39.0409C96.393 38.4038 97.8624 35.9116 97.0079 33.5539C95.2932 28.8227 92.871 24.3692 89.8167 20.348C85.8452 15.1192 80.8826 10.7238 75.2124 7.41289C69.5422 4.10194 63.2754 1.94025 56.7698 1.05124C51.7666 0.367541 46.6976 0.446843 41.7345 1.27873C39.2613 1.69328 37.813 4.19778 38.4501 6.62326C39.0873 9.04874 41.5694 10.4717 44.0505 10.1071C47.8511 9.54855 51.7191 9.52689 55.5402 10.0491C60.8642 10.7766 65.9928 12.5457 70.6331 15.2552C75.2735 17.9648 79.3347 21.5619 82.5849 25.841C84.9175 28.9121 86.7997 32.2913 88.1811 35.8758C89.083 38.2158 91.5421 39.6781 93.9676 39.0409Z"
|
||||
fill="currentFill"
|
||||
/>
|
||||
</svg>
|
||||
<span class="sr-only">Loading...</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
299
src/routes/home/+page.svelte
Normal file
299
src/routes/home/+page.svelte
Normal file
@ -0,0 +1,299 @@
|
||||
<script lang="ts">
|
||||
import { invoke } from '@tauri-apps/api/tauri';
|
||||
import { awaiter } from '$lib/utils';
|
||||
import { onMount } from 'svelte';
|
||||
import type { Config, SyncData } from '$lib/types';
|
||||
import { clipboard, dialog } from '@tauri-apps/api';
|
||||
import { slide } from 'svelte/transition';
|
||||
import { sendNotification } from '@tauri-apps/api/notification';
|
||||
import { platform } from '@tauri-apps/api/os';
|
||||
|
||||
let loadingSync = true;
|
||||
let syncing = false;
|
||||
let syncState = {
|
||||
show: false,
|
||||
syncing: false,
|
||||
error: false,
|
||||
success: false,
|
||||
message: ''
|
||||
};
|
||||
|
||||
let config: Config | null = null;
|
||||
|
||||
onMount(async () => {
|
||||
const [configData, configError] = await awaiter(invoke('get_config') as Promise<Config>);
|
||||
|
||||
if (configError || !configData) {
|
||||
await dialog.message(
|
||||
`Something went wrong while getting the configuration. We've copied the error to your clipboard. Please report this issue on GitHub.\n\nError: ${configError ?? 'Config was null'}\n\nThe application will now close.`,
|
||||
{ title: 'FanslySync | Configuration Error', type: 'error' }
|
||||
);
|
||||
|
||||
await clipboard.writeText(configError);
|
||||
invoke('quit', { code: 1 });
|
||||
return;
|
||||
}
|
||||
|
||||
config = configData;
|
||||
loadingSync = false;
|
||||
});
|
||||
|
||||
async function syncNow() {
|
||||
syncState.error = false;
|
||||
syncState.success = false;
|
||||
syncState.syncing = true;
|
||||
syncState.show = true;
|
||||
|
||||
const [syncData, syncError] = await awaiter(invoke('fansly_sync') as Promise<SyncData>);
|
||||
console.log(syncData, syncError);
|
||||
|
||||
if (syncError || syncData === null) {
|
||||
syncState.syncing = false;
|
||||
syncState.error = true;
|
||||
syncState.message = syncError ?? 'Sync data was null';
|
||||
return;
|
||||
}
|
||||
|
||||
// Return the last sync as unix timestamp
|
||||
config!.last_sync = Date.now();
|
||||
config!.last_sync_data = syncData!;
|
||||
|
||||
const [saveConfigData, saveConfigError] = await awaiter(
|
||||
invoke('save_config', { config }) as Promise<boolean>
|
||||
);
|
||||
if (saveConfigError) {
|
||||
syncState.syncing = false;
|
||||
syncState.error = true;
|
||||
syncState.message = saveConfigError ?? 'Save config data was null';
|
||||
return;
|
||||
}
|
||||
|
||||
syncState.syncing = false;
|
||||
syncState.success = true;
|
||||
|
||||
const platformName = await platform();
|
||||
let soundName;
|
||||
|
||||
if (platformName === 'win32') {
|
||||
soundName = 'ms-winsoundevent:Notification.Default';
|
||||
} else if (platformName === 'darwin') {
|
||||
soundName = 'Ping';
|
||||
} else {
|
||||
soundName = 'completion-sucess';
|
||||
}
|
||||
|
||||
await sendNotification({
|
||||
title: 'FanslySync: Sync Successful!',
|
||||
body: 'Data synced successfully. Please look at the app for more details.',
|
||||
sound: soundName
|
||||
});
|
||||
}
|
||||
</script>
|
||||
|
||||
<div class="container bg-zinc-800 w-screen h-screen">
|
||||
<!-- Top header, Bambu Connect at the left side, settings icon on the right -->
|
||||
<div class="flex justify-between items-center h-16 px-4 bg-zinc-900">
|
||||
<div class="flex items-center">
|
||||
<img src="/fanslySync.png" alt="FanslySynct" class="w-8 h-8" />
|
||||
<h1 class="text-2xl font-bold text-gray-200 ml-2">FanslySync</h1>
|
||||
<span class="text-gray-400 ml-2">v0.1.0</span>
|
||||
</div>
|
||||
<svg
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
fill="none"
|
||||
viewBox="0 0 24 24"
|
||||
stroke-width="1.5"
|
||||
stroke="currentColor"
|
||||
class="w-6 h-6 text-white hidden"
|
||||
>
|
||||
<path
|
||||
stroke-linecap="round"
|
||||
stroke-linejoin="round"
|
||||
d="M9.594 3.94c.09-.542.56-.94 1.11-.94h2.593c.55 0 1.02.398 1.11.94l.213 1.281c.063.374.313.686.645.87.074.04.147.083.22.127.325.196.72.257 1.075.124l1.217-.456a1.125 1.125 0 0 1 1.37.49l1.296 2.247a1.125 1.125 0 0 1-.26 1.431l-1.003.827c-.293.241-.438.613-.43.992a7.723 7.723 0 0 1 0 .255c-.008.378.137.75.43.991l1.004.827c.424.35.534.955.26 1.43l-1.298 2.247a1.125 1.125 0 0 1-1.369.491l-1.217-.456c-.355-.133-.75-.072-1.076.124a6.47 6.47 0 0 1-.22.128c-.331.183-.581.495-.644.869l-.213 1.281c-.09.543-.56.94-1.11.94h-2.594c-.55 0-1.019-.398-1.11-.94l-.213-1.281c-.062-.374-.312-.686-.644-.87a6.52 6.52 0 0 1-.22-.127c-.325-.196-.72-.257-1.076-.124l-1.217.456a1.125 1.125 0 0 1-1.369-.49l-1.297-2.247a1.125 1.125 0 0 1 .26-1.431l1.004-.827c.292-.24.437-.613.43-.991a6.932 6.932 0 0 1 0-.255c.007-.38-.138-.751-.43-.992l-1.004-.827a1.125 1.125 0 0 1-.26-1.43l1.297-2.247a1.125 1.125 0 0 1 1.37-.491l1.216.456c.356.133.751.072 1.076-.124.072-.044.146-.086.22-.128.332-.183.582-.495.644-.869l.214-1.28Z"
|
||||
/>
|
||||
<path
|
||||
stroke-linecap="round"
|
||||
stroke-linejoin="round"
|
||||
d="M15 12a3 3 0 1 1-6 0 3 3 0 0 1 6 0Z"
|
||||
/>
|
||||
</svg>
|
||||
</div>
|
||||
|
||||
<!-- Sync container -->
|
||||
<div class="flex flex-col mt-4 px-3">
|
||||
<h2 class="text-2xl font-bold text-gray-200">Sync</h2>
|
||||
<p class="text-gray-400 mt-1">Manage automatic sync options and manual sync here.</p>
|
||||
<div class="flex flex-wrap mt-2 rounded-lg">
|
||||
{#if loadingSync}
|
||||
<div class="flex flex-col items-center justify-center">
|
||||
<div role="status" class="mb-2">
|
||||
<svg
|
||||
aria-hidden="true"
|
||||
class="w-14 h-14 text-gray-200 animate-spin dark:text-gray-600 fill-blue-600"
|
||||
viewBox="0 0 100 101"
|
||||
fill="none"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
>
|
||||
<path
|
||||
d="M100 50.5908C100 78.2051 77.6142 100.591 50 100.591C22.3858 100.591 0 78.2051 0 50.5908C0 22.9766 22.3858 0.59082 50 0.59082C77.6142 0.59082 100 22.9766 100 50.5908ZM9.08144 50.5908C9.08144 73.1895 27.4013 91.5094 50 91.5094C72.5987 91.5094 90.9186 73.1895 90.9186 50.5908C90.9186 27.9921 72.5987 9.67226 50 9.67226C27.4013 9.67226 9.08144 27.9921 9.08144 50.5908Z"
|
||||
fill="currentColor"
|
||||
/>
|
||||
<path
|
||||
d="M93.9676 39.0409C96.393 38.4038 97.8624 35.9116 97.0079 33.5539C95.2932 28.8227 92.871 24.3692 89.8167 20.348C85.8452 15.1192 80.8826 10.7238 75.2124 7.41289C69.5422 4.10194 63.2754 1.94025 56.7698 1.05124C51.7666 0.367541 46.6976 0.446843 41.7345 1.27873C39.2613 1.69328 37.813 4.19778 38.4501 6.62326C39.0873 9.04874 41.5694 10.4717 44.0505 10.1071C47.8511 9.54855 51.7191 9.52689 55.5402 10.0491C60.8642 10.7766 65.9928 12.5457 70.6331 15.2552C75.2735 17.9648 79.3347 21.5619 82.5849 25.841C84.9175 28.9121 86.7997 32.2913 88.1811 35.8758C89.083 38.2158 91.5421 39.6781 93.9676 39.0409Z"
|
||||
fill="currentFill"
|
||||
/>
|
||||
</svg>
|
||||
<span class="sr-only">Loading...</span>
|
||||
</div>
|
||||
|
||||
<p class="text-gray-400 animate-pulse">Loading sync options, one moment...</p>
|
||||
</div>
|
||||
{:else}
|
||||
<div class="flex flex-col gap-y-2 justify-start">
|
||||
<!-- Automatic sync card -->
|
||||
<div class="relative">
|
||||
<div class="bg-zinc-700 p-4 rounded-lg">
|
||||
<h1 class="text-xl font-bold text-gray-200">Automatic Sync</h1>
|
||||
<p class="text-gray-400 mt-1">
|
||||
Sync content automatically every {config?.sync_interval} hours. Please ensure you have
|
||||
a stable internet connection.
|
||||
</p>
|
||||
<div class="flex mt-2">
|
||||
<button
|
||||
class="bg-blue-600 text-white px-4 py-2 rounded-lg w-full"
|
||||
on:click={() => console.log('Automatic sync clicked')}
|
||||
>
|
||||
Enable
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<div
|
||||
class="absolute top-0 left-0 right-0 bottom-0 bg-white/30 backdrop-blur-sm flex flex-col justify-center items-center rounded-lg"
|
||||
>
|
||||
<svg
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
fill="none"
|
||||
viewBox="0 0 24 24"
|
||||
stroke-width="1.5"
|
||||
stroke="currentColor"
|
||||
class="size-10 text-blue-400"
|
||||
>
|
||||
<path
|
||||
stroke-linecap="round"
|
||||
stroke-linejoin="round"
|
||||
d="m11.25 11.25.041-.02a.75.75 0 0 1 1.063.852l-.708 2.836a.75.75 0 0 0 1.063.853l.041-.021M21 12a9 9 0 1 1-18 0 9 9 0 0 1 18 0Zm-9-3.75h.008v.008H12V8.25Z"
|
||||
/>
|
||||
</svg>
|
||||
<h1 class="text-xl font-bold text-gray-200 ml-2">Automatic Sync is coming soon!</h1>
|
||||
<p class="text-white mt-1">Stay tuned for updates.</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Manual sync card -->
|
||||
<div class=" bg-zinc-700 p-4 rounded-lg">
|
||||
<h1 class="text-xl font-bold text-gray-200">Manual Sync</h1>
|
||||
<p class="text-gray-400 mt-1">
|
||||
Trigger a manual sync now, instead of waiting for an automatic sync.
|
||||
</p>
|
||||
<div class="flex mt-2">
|
||||
<button
|
||||
class="bg-blue-600 text-white px-4 py-2 rounded-lg w-full disabled:opacity-50 disabled:cursor-not-allowed hover:bg-blue-700 transition-all duration-200 ease-in-out"
|
||||
on:click={syncNow}
|
||||
disabled={syncState.syncing}
|
||||
>
|
||||
{syncState.syncing ? 'Syncing...' : 'Sync Now'}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Create a Little bar that animates up when a sync is running -->
|
||||
{#if syncState.show}
|
||||
<div
|
||||
class={`fixed bottom-0 left-0 right-0 text-white p-4
|
||||
${syncState.syncing ? 'bg-blue-500' : syncState.success ? 'bg-green-500' : 'bg-red-500'}
|
||||
|
||||
`}
|
||||
transition:slide={{ duration: 500 }}
|
||||
>
|
||||
<div class="flex items-center">
|
||||
{#if !syncState.success && !syncState.error}
|
||||
<!-- Add loading spinner -->
|
||||
<svg
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
fill="none"
|
||||
viewBox="0 0 24 24"
|
||||
stroke-width="1.5"
|
||||
stroke="currentColor"
|
||||
class="size-6 mr-2 animate-spin"
|
||||
>
|
||||
<path
|
||||
stroke-linecap="round"
|
||||
stroke-linejoin="round"
|
||||
d="M16.023 9.348h4.992v-.001M2.985 19.644v-4.992m0 0h4.992m-4.993 0 3.181 3.183a8.25 8.25 0 0 0 13.803-3.7M4.031 9.865a8.25 8.25 0 0 1 13.803-3.7l3.181 3.182m0-4.991v4.99"
|
||||
/>
|
||||
</svg>
|
||||
|
||||
<!-- Add Syncing title and status subtitle below it -->
|
||||
<div class="flex flex-col">
|
||||
<h1 class="text-lg font-bold">Syncing...</h1>
|
||||
<p class="text-sm">
|
||||
Please wait while we sync your followers and subscriber data. This can take awhile on
|
||||
some connections.
|
||||
</p>
|
||||
</div>
|
||||
{:else if syncState.success}
|
||||
<!-- Add Success title and status subtitle below it -->
|
||||
<div class="flex flex-col">
|
||||
<h1 class="text-lg font-bold">Sync Successful!</h1>
|
||||
<p class="text-sm">
|
||||
Data synced successfully. Please run the import with the following link {syncState.message}
|
||||
to import the data.
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<!-- Add copy and close button -->
|
||||
<div class="flex items-center ml-auto">
|
||||
<button
|
||||
class="bg-white text-blue-600 px-2 py-1 rounded-lg"
|
||||
on:click={() => {
|
||||
clipboard.writeText(syncState.message);
|
||||
}}
|
||||
>
|
||||
Copy
|
||||
</button>
|
||||
<button
|
||||
class="bg-white text-blue-600 px-2 py-1 rounded-lg ml-2"
|
||||
on:click={() => {
|
||||
syncState.show = false;
|
||||
}}
|
||||
>
|
||||
Close
|
||||
</button>
|
||||
</div>
|
||||
{:else}
|
||||
<!-- Add Error title and status subtitle below it -->
|
||||
<div class="flex flex-col">
|
||||
<h1 class="text-lg font-bold">Sync Failed!</h1>
|
||||
<p class="text-sm">
|
||||
An error occurred while syncing your data. Details: {syncState.message}
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<!-- Add close button -->
|
||||
<button
|
||||
class="bg-white text-blue-600 px-2 py-1 rounded-lg ml-auto"
|
||||
on:click={() => {
|
||||
syncState.show = false;
|
||||
}}
|
||||
>
|
||||
Close
|
||||
</button>
|
||||
{/if}
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
266
src/routes/setup/+page.svelte
Normal file
266
src/routes/setup/+page.svelte
Normal file
@ -0,0 +1,266 @@
|
||||
<script lang="ts">
|
||||
let loading = true;
|
||||
let errored = false;
|
||||
let step = 0;
|
||||
let status = 'Contacting Fansly and checking account...';
|
||||
|
||||
let fanslyToken = '';
|
||||
let validationErrors = {
|
||||
fanslyToken: ''
|
||||
};
|
||||
|
||||
import { invoke } from '@tauri-apps/api/tauri';
|
||||
import { dialog, clipboard } from '@tauri-apps/api';
|
||||
import { awaiter } from '$lib/utils';
|
||||
import { onMount } from 'svelte';
|
||||
import type { AccountInfo, Config } from '$lib/types';
|
||||
import NoWorkResult from 'postcss/lib/no-work-result';
|
||||
|
||||
onMount(async () => {
|
||||
const [config, configError] = await awaiter(invoke('get_config'));
|
||||
|
||||
if (configError) {
|
||||
await dialog.message(
|
||||
`Something went wrong while getting the configuration. We've copied the error to your clipboard. Please report this issue on GitHub.\n\nError: ${configError}\n\nThe application will now close.`,
|
||||
{ title: 'BambuConnect | Configuration Error', type: 'error' }
|
||||
);
|
||||
|
||||
await clipboard.writeText(configError);
|
||||
invoke('quit', { code: 1 });
|
||||
return;
|
||||
}
|
||||
|
||||
loading = false;
|
||||
});
|
||||
|
||||
async function loginToFanslyAndFetchData() {
|
||||
const [config, configError] = (await awaiter(invoke('get_config'))) as [Config, any | null];
|
||||
|
||||
if (configError) {
|
||||
await dialog.message(
|
||||
`Something went wrong while getting the configuration. We've copied the error to your clipboard. Please report this issue on GitHub.\n\nError: ${configError}\n\nThe application will now close.`,
|
||||
{ title: 'BambuConnect | Configuration Error', type: 'error' }
|
||||
);
|
||||
|
||||
await clipboard.writeText(configError);
|
||||
invoke('quit', { code: 1 });
|
||||
return;
|
||||
}
|
||||
await invoke('fansly_set_token', { token: fanslyToken });
|
||||
const [me, error] = (await awaiter(invoke('fansly_get_me'))) as [
|
||||
{
|
||||
success: boolean;
|
||||
response: AccountInfo;
|
||||
},
|
||||
any | null
|
||||
];
|
||||
|
||||
if (me === null) {
|
||||
console.error(`Failed to authenticate with Fansly. Error: ${error}`);
|
||||
step = 1;
|
||||
validationErrors.fanslyToken =
|
||||
'We could not authenticate with Fansly. Please check your token and try again.';
|
||||
return;
|
||||
}
|
||||
|
||||
if (!me.success) {
|
||||
console.error(`Failed to authenticate with Fansly. Error: ${me.response}`);
|
||||
step = 1;
|
||||
validationErrors.fanslyToken =
|
||||
'We could not authenticate with Fansly. Please check your token and try again.';
|
||||
return;
|
||||
}
|
||||
|
||||
status = 'Finishing up...';
|
||||
|
||||
console.log('fanslyToken', fanslyToken);
|
||||
config.fansly_token = fanslyToken;
|
||||
config.is_first_run = false;
|
||||
await invoke('save_config', { config });
|
||||
step = 3;
|
||||
}
|
||||
|
||||
function validateLoginForm() {
|
||||
let hasErrors = false;
|
||||
|
||||
if (fanslyToken === '') {
|
||||
validationErrors.fanslyToken = 'Please enter your Fansly token.';
|
||||
hasErrors = true;
|
||||
} else {
|
||||
validationErrors.fanslyToken = '';
|
||||
}
|
||||
|
||||
if (hasErrors) {
|
||||
return;
|
||||
}
|
||||
|
||||
step = 2;
|
||||
loginToFanslyAndFetchData();
|
||||
}
|
||||
</script>
|
||||
|
||||
<div class="container bg-zinc-800 w-screen h-screen">
|
||||
<!-- Centered loading spinner -->
|
||||
<div class="flex flex-col justify-center items-center h-screen">
|
||||
{#if loading}
|
||||
<div role="status">
|
||||
<svg
|
||||
aria-hidden="true"
|
||||
class="w-14 h-14 text-gray-200 animate-spin dark:text-gray-600 fill-blue-600"
|
||||
viewBox="0 0 100 101"
|
||||
fill="none"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
>
|
||||
<path
|
||||
d="M100 50.5908C100 78.2051 77.6142 100.591 50 100.591C22.3858 100.591 0 78.2051 0 50.5908C0 22.9766 22.3858 0.59082 50 0.59082C77.6142 0.59082 100 22.9766 100 50.5908ZM9.08144 50.5908C9.08144 73.1895 27.4013 91.5094 50 91.5094C72.5987 91.5094 90.9186 73.1895 90.9186 50.5908C90.9186 27.9921 72.5987 9.67226 50 9.67226C27.4013 9.67226 9.08144 27.9921 9.08144 50.5908Z"
|
||||
fill="currentColor"
|
||||
/>
|
||||
<path
|
||||
d="M93.9676 39.0409C96.393 38.4038 97.8624 35.9116 97.0079 33.5539C95.2932 28.8227 92.871 24.3692 89.8167 20.348C85.8452 15.1192 80.8826 10.7238 75.2124 7.41289C69.5422 4.10194 63.2754 1.94025 56.7698 1.05124C51.7666 0.367541 46.6976 0.446843 41.7345 1.27873C39.2613 1.69328 37.813 4.19778 38.4501 6.62326C39.0873 9.04874 41.5694 10.4717 44.0505 10.1071C47.8511 9.54855 51.7191 9.52689 55.5402 10.0491C60.8642 10.7766 65.9928 12.5457 70.6331 15.2552C75.2735 17.9648 79.3347 21.5619 82.5849 25.841C84.9175 28.9121 86.7997 32.2913 88.1811 35.8758C89.083 38.2158 91.5421 39.6781 93.9676 39.0409Z"
|
||||
fill="currentFill"
|
||||
/>
|
||||
</svg>
|
||||
<span class="sr-only">Loading...</span>
|
||||
</div>
|
||||
|
||||
<h1 class="text-2xl font-bold mt-2 text-white">Setup is loading...</h1>
|
||||
{/if}
|
||||
|
||||
{#if errored}
|
||||
<svg
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
fill="none"
|
||||
viewBox="0 0 24 24"
|
||||
stroke-width="1.5"
|
||||
stroke="currentColor"
|
||||
class="w-12 h-12 text-red-500 dark:text-red-400"
|
||||
>
|
||||
<path
|
||||
stroke-linecap="round"
|
||||
stroke-linejoin="round"
|
||||
d="M12 9v3.75m-9.303 3.376c-.866 1.5.217 3.374 1.948 3.374h14.71c1.73 0 2.813-1.874 1.948-3.374L13.949 3.378c-.866-1.5-3.032-1.5-3.898 0L2.697 16.126ZM12 15.75h.007v.008H12v-.008Z"
|
||||
/>
|
||||
</svg>
|
||||
|
||||
<h1 class="text-2xl font-bold mt-2 text-white">Oops!</h1>
|
||||
<p class="text-red-500 mt-2 max-w-[30em]">
|
||||
An error was encountered while initializing the setup, please try closing and reopening
|
||||
FanslySync.
|
||||
</p>
|
||||
{/if}
|
||||
|
||||
{#if !loading && !errored}
|
||||
{#if step === 0}
|
||||
<h1 class="text-2xl font-bold mt-2 text-white">Welcome to FanslySync!</h1>
|
||||
<p class="text-gray-200 break-words max-w-[30em]">
|
||||
Because this is your first time running FanslySync, we need to set up the connection to
|
||||
your Fansly account. Click the button below to get started.
|
||||
</p>
|
||||
|
||||
{#if errored}
|
||||
<p class="text-red-500 mt-2">
|
||||
An error occurred while initializing the setup. Please try again.
|
||||
</p>
|
||||
{/if}
|
||||
|
||||
{#if !loading}
|
||||
<button
|
||||
on:click={() => {
|
||||
step = 1;
|
||||
}}
|
||||
class="mt-4 bg-blue-600 text-white px-4 py-2 rounded-md hover:bg-blue-700 transition-all duration-200 ease-in-out"
|
||||
>
|
||||
Begin Setup
|
||||
</button>
|
||||
{/if}
|
||||
{:else if step === 1}
|
||||
<h1 class="text-2xl font-bold mt-2 text-white">Authenticate with Fansly</h1>
|
||||
<p class="text-gray-200 break-words max-w-[30em]">
|
||||
To establish a secure connection with Fansly, we require your Fansly Authentication Token.
|
||||
We do not transmit this token to our servers and it is only used to authenticate with
|
||||
Fansly and fetch data locally. <br /> <br />
|
||||
For more information on how to get your Fansly Authentication Token, please visit our documentation,
|
||||
or join our Discord server if you need help or have any questions.
|
||||
</p>
|
||||
|
||||
<label for="username" class="text-gray-200 mt-4"> Fansly Authentication Token </label>
|
||||
<input
|
||||
id="fanslyToken"
|
||||
class="w-full bg-zinc-700 text-gray-200 px-4 py-2 rounded-md mt-2 max-w-96"
|
||||
type="text"
|
||||
autocomplete="current-password"
|
||||
bind:value={fanslyToken}
|
||||
/>
|
||||
|
||||
{#if validationErrors.fanslyToken !== ''}
|
||||
<p class="text-red-500 mt-2">{validationErrors.fanslyToken}</p>
|
||||
{/if}
|
||||
|
||||
{#if !loading}
|
||||
<button
|
||||
on:click={validateLoginForm}
|
||||
class="mt-4 bg-blue-600 text-white px-4 py-2 rounded-md hover:bg-blue-700 transition-all duration-200 ease-in-out"
|
||||
>
|
||||
Authenticate and setup connection
|
||||
</button>
|
||||
{/if}
|
||||
{:else if step == 2}
|
||||
<div role="status">
|
||||
<svg
|
||||
aria-hidden="true"
|
||||
class="w-14 h-14 text-gray-200 animate-spin dark:text-gray-600 fill-blue-600"
|
||||
viewBox="0 0 100 101"
|
||||
fill="none"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
>
|
||||
<path
|
||||
d="M100 50.5908C100 78.2051 77.6142 100.591 50 100.591C22.3858 100.591 0 78.2051 0 50.5908C0 22.9766 22.3858 0.59082 50 0.59082C77.6142 0.59082 100 22.9766 100 50.5908ZM9.08144 50.5908C9.08144 73.1895 27.4013 91.5094 50 91.5094C72.5987 91.5094 90.9186 73.1895 90.9186 50.5908C90.9186 27.9921 72.5987 9.67226 50 9.67226C27.4013 9.67226 9.08144 27.9921 9.08144 50.5908Z"
|
||||
fill="currentColor"
|
||||
/>
|
||||
<path
|
||||
d="M93.9676 39.0409C96.393 38.4038 97.8624 35.9116 97.0079 33.5539C95.2932 28.8227 92.871 24.3692 89.8167 20.348C85.8452 15.1192 80.8826 10.7238 75.2124 7.41289C69.5422 4.10194 63.2754 1.94025 56.7698 1.05124C51.7666 0.367541 46.6976 0.446843 41.7345 1.27873C39.2613 1.69328 37.813 4.19778 38.4501 6.62326C39.0873 9.04874 41.5694 10.4717 44.0505 10.1071C47.8511 9.54855 51.7191 9.52689 55.5402 10.0491C60.8642 10.7766 65.9928 12.5457 70.6331 15.2552C75.2735 17.9648 79.3347 21.5619 82.5849 25.841C84.9175 28.9121 86.7997 32.2913 88.1811 35.8758C89.083 38.2158 91.5421 39.6781 93.9676 39.0409Z"
|
||||
fill="currentFill"
|
||||
/>
|
||||
</svg>
|
||||
<span class="sr-only">Loading...</span>
|
||||
</div>
|
||||
|
||||
<h1 class="text-2xl font-bold mt-2 text-white">We are working our magic!</h1>
|
||||
<p class="text-gray-200 break-words max-w-[30em]">
|
||||
We are now authenticating with Fansly and fetching your data. This may take a few moments.
|
||||
</p>
|
||||
<p class="text-gray-200 break-words max-w-[30em]">
|
||||
{status}
|
||||
</p>
|
||||
{:else if step === 3}
|
||||
<svg
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
fill="none"
|
||||
viewBox="0 0 24 24"
|
||||
stroke-width="1.5"
|
||||
stroke="currentColor"
|
||||
class="w-12 h-12 text-green-500 dark:text-green-400"
|
||||
>
|
||||
<path
|
||||
stroke-linecap="round"
|
||||
stroke-linejoin="round"
|
||||
d="M9 12.75 11.25 15 15 9.75M21 12a9 9 0 1 1-18 0 9 9 0 0 1 18 0Z"
|
||||
/>
|
||||
</svg>
|
||||
<h1 class="text-2xl font-bold mt-2 text-white">Setup Complete!</h1>
|
||||
<p class="text-gray-200 break-words max-w-[30em]">
|
||||
You're all set! FanslySync is now connected to your Fansly account and is ready to use.
|
||||
</p>
|
||||
|
||||
<button
|
||||
on:click={() => {
|
||||
window.location.href = '/home';
|
||||
}}
|
||||
class="mt-4 bg-blue-600 text-white px-4 py-2 rounded-md hover:bg-blue-700 transition-all duration-200 ease-in-out"
|
||||
>
|
||||
Finish
|
||||
</button>
|
||||
{/if}
|
||||
{/if}
|
||||
</div>
|
||||
</div>
|
Reference in New Issue
Block a user