Compare commits
4
Commits
12208b78ae
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
767b0417c8
|
||
|
|
0e4eeb5f19
|
||
|
|
40ca26d07d
|
||
|
|
c2b7ee0f08
|
No files matched your search
+2
-1
@@ -1,5 +1,6 @@
|
|||||||
{
|
{
|
||||||
"useTabs": true,
|
"useTabs": false,
|
||||||
|
"tabWidth": 2,
|
||||||
"singleQuote": true,
|
"singleQuote": true,
|
||||||
"trailingComma": "none",
|
"trailingComma": "none",
|
||||||
"printWidth": 100,
|
"printWidth": 100,
|
||||||
|
|||||||
@@ -2,18 +2,6 @@
|
|||||||
|
|
||||||
File storage and sharing service.
|
File storage and sharing service.
|
||||||
|
|
||||||
## Creating a project
|
|
||||||
|
|
||||||
If you're seeing this, you've probably already done this step. Congrats!
|
|
||||||
|
|
||||||
```bash
|
|
||||||
# create a new project in the current directory
|
|
||||||
npm create svelte@latest
|
|
||||||
|
|
||||||
# create a new project in my-app
|
|
||||||
npm create svelte@latest my-app
|
|
||||||
```
|
|
||||||
|
|
||||||
## Developing
|
## Developing
|
||||||
|
|
||||||
Once you've created a project and installed dependencies with `npm install` (or `pnpm install` or `yarn`), start a development server:
|
Once you've created a project and installed dependencies with `npm install` (or `pnpm install` or `yarn`), start a development server:
|
||||||
|
|||||||
+8
-1
@@ -16,19 +16,26 @@
|
|||||||
"@sveltejs/kit": "^2.0.0",
|
"@sveltejs/kit": "^2.0.0",
|
||||||
"@sveltejs/vite-plugin-svelte": "^3.0.0",
|
"@sveltejs/vite-plugin-svelte": "^3.0.0",
|
||||||
"@types/eslint": "^8.56.7",
|
"@types/eslint": "^8.56.7",
|
||||||
|
"autoprefixer": "^10.4.19",
|
||||||
"eslint": "^9.0.0",
|
"eslint": "^9.0.0",
|
||||||
"eslint-config-prettier": "^9.1.0",
|
"eslint-config-prettier": "^9.1.0",
|
||||||
"eslint-plugin-svelte": "^2.36.0",
|
"eslint-plugin-svelte": "^2.36.0",
|
||||||
|
"filesize": "^10.1.2",
|
||||||
"globals": "^15.0.0",
|
"globals": "^15.0.0",
|
||||||
|
"postcss": "^8.4.38",
|
||||||
"prettier": "^3.1.1",
|
"prettier": "^3.1.1",
|
||||||
"prettier-plugin-svelte": "^3.1.2",
|
"prettier-plugin-svelte": "^3.1.2",
|
||||||
"svelte": "^4.2.7",
|
"svelte": "^4.2.7",
|
||||||
"svelte-check": "^3.6.0",
|
"svelte-check": "^3.6.0",
|
||||||
|
"tailwindcss": "^3.4.4",
|
||||||
"tslib": "^2.4.1",
|
"tslib": "^2.4.1",
|
||||||
"typescript": "^5.0.0",
|
"typescript": "^5.0.0",
|
||||||
"typescript-eslint": "^8.0.0-alpha.20",
|
"typescript-eslint": "^8.0.0-alpha.20",
|
||||||
"vite": "^5.0.3"
|
"vite": "^5.0.3"
|
||||||
},
|
},
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"packageManager": "pnpm@9.3.0+sha256.e1f9e8d1a16607a46dd3c158b5f7a7dc7945501d1c6222d454d63d033d1d918f"
|
"packageManager": "pnpm@9.3.0+sha256.e1f9e8d1a16607a46dd3c158b5f7a7dc7945501d1c6222d454d63d033d1d918f",
|
||||||
|
"dependencies": {
|
||||||
|
"pocketbase": "^0.21.3"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Generated
+534
-5
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,6 @@
|
|||||||
|
export default {
|
||||||
|
plugins: {
|
||||||
|
tailwindcss: {},
|
||||||
|
autoprefixer: {},
|
||||||
|
},
|
||||||
|
}
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
@tailwind base;
|
||||||
|
@tailwind components;
|
||||||
|
@tailwind utilities;
|
||||||
|
|
||||||
|
html,
|
||||||
|
body {
|
||||||
|
height: 100%;
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
Vendored
+38
-7
@@ -1,13 +1,44 @@
|
|||||||
// See https://kit.svelte.dev/docs/types#app
|
// See https://kit.svelte.dev/docs/types#app
|
||||||
// for information about these interfaces
|
// for information about these interfaces
|
||||||
declare global {
|
declare global {
|
||||||
namespace App {
|
namespace App {
|
||||||
// interface Error {}
|
// interface Error {}
|
||||||
// interface Locals {}
|
// interface Locals {}
|
||||||
// interface PageData {}
|
// interface PageData {}
|
||||||
// interface PageState {}
|
// interface PageState {}
|
||||||
// interface Platform {}
|
// interface Platform {}
|
||||||
}
|
}
|
||||||
|
declare type FileDropEvent = import('filedrop-svelte/event').FileDropEvent;
|
||||||
|
declare type FileDropSelectEvent = import('filedrop-svelte/event').FileDropSelectEvent;
|
||||||
|
declare type FileDropDragEvent = import('filedrop-svelte/event').FileDropDragEvent;
|
||||||
|
declare namespace svelte.JSX {
|
||||||
|
interface HTMLAttributes<T> {
|
||||||
|
onfiledrop?: (event: CustomEvent<FileDropSelectEvent> & { target: EventTarget & T }) => void;
|
||||||
|
onfiledragenter?: (
|
||||||
|
event: CustomEvent<FileDropDragEvent> & { target: EventTarget & T }
|
||||||
|
) => void;
|
||||||
|
onfiledragleave?: (
|
||||||
|
event: CustomEvent<FileDropDragEvent> & { target: EventTarget & T }
|
||||||
|
) => void;
|
||||||
|
onfiledragover?: (
|
||||||
|
event: CustomEvent<FileDropDragEvent> & { target: EventTarget & T }
|
||||||
|
) => void;
|
||||||
|
onfiledialogcancel?: (
|
||||||
|
event: CustomEvent<FileDropEvent> & { target: EventTarget & T }
|
||||||
|
) => void;
|
||||||
|
onfiledialogclose?: (event: CustomEvent<FileDropEvent> & { target: EventTarget & T }) => void;
|
||||||
|
onfiledialogopen?: (event: CustomEvent<FileDropEvent> & { target: EventTarget & T }) => void;
|
||||||
|
onwindowfiledragenter?: (
|
||||||
|
event: CustomEvent<FileDropDragEvent> & { target: EventTarget & T }
|
||||||
|
) => void;
|
||||||
|
onwindowfiledragleave?: (
|
||||||
|
event: CustomEvent<FileDropDragEvent> & { target: EventTarget & T }
|
||||||
|
) => void;
|
||||||
|
onwindowfiledragover?: (
|
||||||
|
event: CustomEvent<FileDropDragEvent> & { target: EventTarget & T }
|
||||||
|
) => void;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export {};
|
export {};
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
import Pocketbase from 'pocketbase';
|
||||||
|
import { PUBLIC_POCKETBASE_URL } from '$env/static/public';
|
||||||
|
|
||||||
|
const client = new Pocketbase(PUBLIC_POCKETBASE_URL)
|
||||||
|
export default client;
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
<script>
|
||||||
|
import "../app.css";
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<slot />
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
export const actions = {
|
||||||
|
default: async (event) => {
|
||||||
|
// upload file
|
||||||
|
console.log(event);
|
||||||
|
}
|
||||||
|
};
|
||||||
+120
-2
@@ -1,2 +1,120 @@
|
|||||||
<h1>Welcome to SvelteKit</h1>
|
<script lang="ts">
|
||||||
<p>Visit <a href="https://kit.svelte.dev">kit.svelte.dev</a> to read the documentation</p>
|
import { PUBLIC_POCKETBASE_URL } from '$env/static/public';
|
||||||
|
import { filesize } from 'filesize';
|
||||||
|
|
||||||
|
let file: File | undefined = undefined;
|
||||||
|
let percent = 0;
|
||||||
|
let isDragging = false;
|
||||||
|
|
||||||
|
let completeURL: string | undefined;
|
||||||
|
|
||||||
|
const handleFormClick = () => {
|
||||||
|
if (percent > 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
let input = document.createElement('input');
|
||||||
|
input.type = 'file';
|
||||||
|
input.accept = '*';
|
||||||
|
input.onchange = (e) => {
|
||||||
|
if (input.files) {
|
||||||
|
file = input.files[0];
|
||||||
|
handleFileChange(file);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
input.click();
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleFileChange = (file: File) => {
|
||||||
|
const formData = new FormData();
|
||||||
|
formData.append('file', file);
|
||||||
|
|
||||||
|
let xhr = new XMLHttpRequest();
|
||||||
|
xhr.upload.onprogress = function (event) {
|
||||||
|
percent = Math.round((100 * event.loaded) / event.total);
|
||||||
|
// do something with the percentage
|
||||||
|
};
|
||||||
|
|
||||||
|
xhr.onreadystatechange = (event) => {
|
||||||
|
if (xhr.readyState === 4 && xhr.status < 400) {
|
||||||
|
const response = JSON.parse(xhr.responseText);
|
||||||
|
completeURL = `${window.location.origin}/files/${response.id}`;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
xhr.open('POST', `${PUBLIC_POCKETBASE_URL}/api/collections/uploads/records`);
|
||||||
|
xhr.send(formData);
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleDrop = (
|
||||||
|
e: DragEvent & {
|
||||||
|
currentTarget: EventTarget & HTMLDivElement;
|
||||||
|
}
|
||||||
|
) => {
|
||||||
|
e.preventDefault();
|
||||||
|
if (e.dataTransfer?.files) {
|
||||||
|
file = e.dataTransfer.files[0];
|
||||||
|
handleFileChange(file);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleDragEnter = (
|
||||||
|
e: DragEvent & {
|
||||||
|
currentTarget: EventTarget & HTMLDivElement;
|
||||||
|
}
|
||||||
|
) => {
|
||||||
|
isDragging = true;
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleDragLeave = (
|
||||||
|
e: DragEvent & {
|
||||||
|
currentTarget: EventTarget & HTMLDivElement;
|
||||||
|
}
|
||||||
|
) => {
|
||||||
|
isDragging = false;
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleDragOver = (
|
||||||
|
e: DragEvent & {
|
||||||
|
currentTarget: EventTarget & HTMLDivElement;
|
||||||
|
}
|
||||||
|
) => {
|
||||||
|
e.preventDefault();
|
||||||
|
};
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<main class="flex flex-col items-center h-full w-full">
|
||||||
|
<h1 class="text-4xl font-bold mt-4">KatStash</h1>
|
||||||
|
|
||||||
|
<h2 class="text-2xl font-semibold mt-2">
|
||||||
|
Uploads up to 200 MB are allowed. Contact SphericalKat for more details
|
||||||
|
</h2>
|
||||||
|
|
||||||
|
<!-- svelte-ignore a11y-no-noninteractive-element-interactions -->
|
||||||
|
<!-- svelte-ignore a11y-click-events-have-key-events -->
|
||||||
|
<!-- svelte-ignore a11y-no-static-element-interactions -->
|
||||||
|
<div
|
||||||
|
on:dragenter={handleDragEnter}
|
||||||
|
on:dragleave={handleDragLeave}
|
||||||
|
on:drop={handleDrop}
|
||||||
|
on:dragover={handleDragOver}
|
||||||
|
on:click={handleFormClick}
|
||||||
|
class:border-dashed={percent === 0}
|
||||||
|
class:cursor-pointer={percent === 0 && !completeURL}
|
||||||
|
class="h-48 w-[650px] mt-40 border-2 border-slate-500 rounded-lg flex items-center justify-center cursor-pointer"
|
||||||
|
>
|
||||||
|
<div class="block">
|
||||||
|
{#if percent > 0 && !completeURL}
|
||||||
|
<span class="text-slate-500 px-16">Uploading {percent}%</span>
|
||||||
|
{:else if percent < 100 && !completeURL}
|
||||||
|
<span class="text-slate-500 px-16">Select or drop a file</span>
|
||||||
|
{:else}
|
||||||
|
<div class="text-slate-500 px-16">
|
||||||
|
Upload complete! Access your file at <a class="underline text-blue-500" href={completeURL}
|
||||||
|
>{completeURL}</a
|
||||||
|
>
|
||||||
|
</div>
|
||||||
|
{/if}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</main>
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
import { redirect } from '@sveltejs/kit';
|
||||||
|
import Pocketbase from 'pocketbase';
|
||||||
|
import { PUBLIC_POCKETBASE_URL } from '$env/static/public';
|
||||||
|
|
||||||
|
export async function GET({ params: { slug } }) {
|
||||||
|
let fileUrl = null;
|
||||||
|
try {
|
||||||
|
const pocketbase = new Pocketbase(PUBLIC_POCKETBASE_URL);
|
||||||
|
const record = await pocketbase.collection('uploads').getOne(slug);
|
||||||
|
fileUrl = new URL(
|
||||||
|
`${PUBLIC_POCKETBASE_URL}/api/files/${record.collectionId}/${record.id}/${record.file}`
|
||||||
|
);
|
||||||
|
} catch (error) {
|
||||||
|
console.error(error);
|
||||||
|
return redirect(307, '/404');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (fileUrl) {
|
||||||
|
redirect(301, fileUrl);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
/** @type {import('tailwindcss').Config} */
|
||||||
|
export default {
|
||||||
|
content: ['./src/**/*.{html,js,svelte,ts}'],
|
||||||
|
theme: {
|
||||||
|
extend: {},
|
||||||
|
},
|
||||||
|
plugins: [],
|
||||||
|
}
|
||||||
|
|
||||||
Reference in new issue
Block a user