aboutsummaryrefslogtreecommitdiff
path: root/static
diff options
context:
space:
mode:
Diffstat (limited to 'static')
-rw-r--r--static/api/images.js43
-rw-r--r--static/index.js26
-rw-r--r--static/pages/settings/index.js4
3 files changed, 51 insertions, 22 deletions
diff --git a/static/api/images.js b/static/api/images.js
index 915aae6..4a41a3c 100644
--- a/static/api/images.js
+++ b/static/api/images.js
@@ -1,6 +1,43 @@
import * as sfw from 'sfw';
const { Input } = sfw.element.native;
+class FileUploader {
+ constructor(url) {
+ this.onprogress = () => {}
+ this.ondone = () => {}
+ this.url = url;
+ this.sessions = [];
+ }
+
+ send(...files) {
+ let count = 0;
+ this.sessions = this.sessions.concat(files.map(
+ file => new Promise((resolve) => {
+ const xhr = new XMLHttpRequest();
+ xhr.upload.addEventListener("progress", (event) => {
+ if (event.lengthComputable) {
+ this.onprogress(file, event.loaded, event.total)
+ }
+ });
+
+ xhr.addEventListener("loadend", () => {
+ count += 1;
+
+ resolve(xhr.readyState === 4 && xhr.status === 200);
+
+ if (count == files.length) {
+ this.ondone();
+ }
+ });
+
+ xhr.open("POST", this.url, true);
+ xhr.setRequestHeader("Content-Type", "application/octet-stream");
+ xhr.send(file.slice());
+ })
+ ));
+ }
+}
+
export async function upload_to_timeline() {
const input = Input.new({
type: 'file',
@@ -8,6 +45,12 @@ export async function upload_to_timeline() {
accept: 'image/jpeg',
})
input.click();
+
+ const uploader = new FileUploader('/api/image/upload');
+
+ input.onchange = async () => {
+ uploader.send(...input.files);
+ }
}
export async function upload_to_profile() {
diff --git a/static/index.js b/static/index.js
index e9ef859..90b5ffd 100644
--- a/static/index.js
+++ b/static/index.js
@@ -16,20 +16,6 @@ sfw.theme.add_css(await sfw.css(import.meta.url, './index.css'));
const image_viewer = ImageViewer.new();
-[
- '/images/0001.jpg',
- '/images/0002.jpg',
- '/images/0003.jpg',
- '/images/0004.jpg',
- '/images/0005.jpg',
- '/images/0006.jpg',
- '/images/0007.jpg',
- '/images/0008.jpg',
- '/images/0009.jpg',
- '/images/0010.jpg',
-].forEach(url => image_viewer.add(url))
-
-
const login = LoginView.new({
onlogin: async (user, password) => {
if (await api.auth.login(user, password)) {
@@ -102,8 +88,10 @@ document.body.append(
month_select,
);
-if (await api.session.is_valid()) {
- login.hide();
-} else {
- login.focus();
-}
+
+login.hide();
+//if (await api.session.is_valid()) {
+// login.hide();
+//} else {
+// login.focus();
+//}
diff --git a/static/pages/settings/index.js b/static/pages/settings/index.js
index 6a0e231..c11a3e9 100644
--- a/static/pages/settings/index.js
+++ b/static/pages/settings/index.js
@@ -23,9 +23,7 @@ export default class SettingsView extends sfw.element.Container {
Div.new({
id: 'image-container',
children: [
- Img.new({
- src: '/images/0010.jpg',
- }),
+ Img.new(),
]
}),
Div.new({