Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Websockets on FileView #29

Closed
wants to merge 8 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
#28 - POC for listening for updates on FileView
kristianbinau committed Oct 11, 2023
commit 3ba7784e085a2e7cb5d3f5097d1876926356ae78
2 changes: 2 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -8,3 +8,5 @@ PUBLIC_API_URL="http://localhost:3000/api/"
JWT_PUBLIC_KEY="-----BEGIN PUBLIC KEY-----
MCowBQYDK2VwAyEA/nqSs2DZmox+sRNR9d9XdaO3C2yJABIO5gdJlBcswNI=
-----END PUBLIC KEY-----"

PUBLIC_PUSHER_APP_KEY="3a4575271634ad5a09ef"
14 changes: 14 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -44,6 +44,7 @@
"flowbite-typography": "^1.0.3",
"jose": "^4.15.1",
"nanostores": "^0.9.3",
"pusher-js": "^8.3.0",
"tailwind-scrollbar": "^3.0.5",
"tailwindcss": "^3.3.3",
"typescript": "^5.2.2",
26 changes: 26 additions & 0 deletions src/components/item/Browser.vue
Original file line number Diff line number Diff line change
@@ -72,12 +72,17 @@ import ContextMenu from '@components/base/contextMenu.vue';
import BaseToast, { ToastType } from '@components/base/toast.vue';
import { t } from '@lib/i18n';
import { isModalOpen } from '@stores/modal';
import Pusher from 'pusher-js';

const props = defineProps({
modelValue: {
type: Object as PropType<FolderType>,
required: false,
},
user: {
type: Object as PropType<User>,
required: true,
},
});

const fileBrowserContextMenu = ref<InstanceType<typeof ContextMenu>>();
@@ -186,4 +191,25 @@ async function uploadFiles(e: Event) {
}
});
}

/**
* Live Updates
*/
Pusher.logToConsole = true;

let pusher = new Pusher(import.meta.env.PUBLIC_PUSHER_APP_KEY, {
cluster: import.meta.env.PUBLIC_PUSHER_APP_CLUSTER,
});

const channelName = FolderClass.isFolder(props.modelValue)
? `browser-folder-${props.modelValue.id}`
: `browser-root-${await crypto.subtle.digest(
'SHA-256',
new TextEncoder().encode(props.user.email),
)}`;

var channel = pusher.subscribe(channelName);
channel.bind('update', function (data: any) {
alert(JSON.stringify(data));
});
</script>
2 changes: 2 additions & 0 deletions src/env.d.ts
Original file line number Diff line number Diff line change
@@ -13,6 +13,8 @@ interface ImportMetaEnv {
readonly PUBLIC_LOCAL_DEVELOPMENT_API_URL: string | undefined;
readonly JWT_PUBLIC_KEY: string;
readonly NODE_BUILD: boolean | undefined;
readonly PUBLIC_PUSHER_APP_KEY: string;
readonly PUBLIC_PUSHER_APP_CLUSTER: string;
}

interface ImportMeta {
2 changes: 1 addition & 1 deletion src/pages/u/folder/[id].astro
Original file line number Diff line number Diff line change
@@ -38,6 +38,6 @@ const user = Astro.locals.user as User;

<LayoutSidebar user={user}>
<div class="h-screen">
<Browser modelValue={folder} client:only />
<Browser modelValue={folder} user={user} client:only />
</div>
</LayoutSidebar>
2 changes: 1 addition & 1 deletion src/pages/u/index.astro
Original file line number Diff line number Diff line change
@@ -9,6 +9,6 @@ const user = Astro.locals.user as User;

<LayoutSidebar user={user}>
<div class="h-screen">
<Browser modelValue={{}} client:only />
<Browser modelValue={{}} user={user} client:only />
</div>
</LayoutSidebar>