Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
I
image-board-svelte
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Trirst
image-board-svelte
Commits
a2bad358
Commit
a2bad358
authored
Oct 16, 2021
by
Trirst
Browse files
Options
Downloads
Patches
Plain Diff
Image metadata fields in upload page
parent
54b8b3dd
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/routes/Upload.svelte
+58
-6
58 additions, 6 deletions
src/routes/Upload.svelte
with
58 additions
and
6 deletions
src/routes/Upload.svelte
+
58
−
6
View file @
a2bad358
...
@@ -5,7 +5,7 @@
...
@@ -5,7 +5,7 @@
let
imageUpload
;
let
imageUpload
;
let
previews
=
[];
let
previews
=
[];
let
forms
=
[];
const
acceptedTypes
=
[
"
image/png
"
,
"
image/jpeg
"
,
"
image/gif
"
];
const
acceptedTypes
=
[
"
image/png
"
,
"
image/jpeg
"
,
"
image/gif
"
];
function
validImageTypes
(
file
)
{
function
validImageTypes
(
file
)
{
...
@@ -21,11 +21,17 @@
...
@@ -21,11 +21,17 @@
}
}
}
}
function
postImages
()
{
async
function
postImages
()
{
let
formData
=
new
FormData
();
let
formData
=
new
FormData
();
let
i
=
0
;
for
(
const
file
of
imageUpload
.
files
)
{
for
(
const
file
of
imageUpload
.
files
)
{
formData
.
set
(
"
image
"
,
file
);
formData
.
set
(
"
image
"
,
file
);
post1Image
(
formData
);
const
imageMetadata
=
await
post1Image
(
formData
);
updateImageMetadata
(
imageMetadata
.
snowflake
,
serializeForm
(
forms
[
i
])
);
i
++
;
}
}
imageUpload
.
value
=
null
;
imageUpload
.
value
=
null
;
previews
=
[];
previews
=
[];
...
@@ -42,6 +48,22 @@
...
@@ -42,6 +48,22 @@
const
imageMetadata
=
await
fetchAPI
(
paths
.
Image
,
options
);
const
imageMetadata
=
await
fetchAPI
(
paths
.
Image
,
options
);
return
imageMetadata
;
return
imageMetadata
;
}
}
// Serialize image metada fields into JSON string that can be sent to API endpoints
function
serializeForm
(
form
)
{
return
JSON
.
stringify
(
Object
.
fromEntries
(
new
FormData
(
form
)));
}
function
updateImageMetadata
(
snowflake
,
metadata
)
{
const
options
=
{
method
:
"
PATCH
"
,
headers
:
{
secret
:
$user
.
secret
,
},
body
:
metadata
,
};
fetchAPI
(
paths
.
ImageField
(
snowflake
),
options
);
}
</script>
</script>
<main
class=
"flex flex-col items-center mx-auto max-w-4xl"
>
<main
class=
"flex flex-col items-center mx-auto max-w-4xl"
>
...
@@ -55,8 +77,38 @@
...
@@ -55,8 +77,38 @@
/>
/>
<button
on:click=
{
postImages
}
>
Submit
</button>
<button
on:click=
{
postImages
}
>
Submit
</button>
</div>
</div>
<!-- {(console.log(forms), "")} -->
{
#each
previews
as
preview
}
{
#each
previews
as
preview
,
i
}
<img
src=
{
preview
}
alt=
""
class=
"max-w-md"
/>
<div
class=
"flex flex-row space-x-6 m-4"
>
<form
class=
"flex flex-col flex-1 space-y-6"
bind:this=
{
forms
[
i
]
}
>
<input
type=
"text"
placeholder=
"Source"
name=
"source"
autocomplete=
"off"
/>
<input
type=
"text"
placeholder=
"Parent"
name=
"parent"
autocomplete=
"off"
/>
<textarea
type=
"text"
placeholder=
"Commentary"
name=
"commentary"
autocomplete=
"off"
class=
"max-h-full resize-none flex-1"
/>
<textarea
type=
"text"
placeholder=
"Commentary translation"
name=
"commentary_translation"
autocomplete=
"off"
class=
"max-h-full resize-none flex-1"
/>
</form>
<img
src=
{
preview
}
alt=
""
class=
"max-w-xs"
/>
</div>
{
/each
}
{
/each
}
</main>
</main>
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment