Compare commits
17 Commits
dfe1bdfeb4
...
v0.1.2
Author | SHA1 | Date | |
---|---|---|---|
6038dc2273
|
|||
316c79cb88
|
|||
0f5341835f
|
|||
0196476370
|
|||
1f81d48aad
|
|||
e3ac9e9b41
|
|||
b7923c9091
|
|||
dcc46f679b
|
|||
a8a6292d2b
|
|||
5abc1fe75a
|
|||
7cfd3bb1de
|
|||
9a5c432186
|
|||
565b183d17
|
|||
758495e3ee
|
|||
5afc375042
|
|||
3cb49d005e
|
|||
d4c83e27d2
|
3
.gitignore
vendored
3
.gitignore
vendored
@@ -1 +1,2 @@
|
||||
go.work
|
||||
/go.work
|
||||
/bin
|
||||
|
3
.gitmodules
vendored
Normal file
3
.gitmodules
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
[submodule "src/webui/translation-json"]
|
||||
path = src/webui/translation-json
|
||||
url = https://gitea.armuli.eu/museum-digital/translation-json.git
|
674
LICENSE
Normal file
674
LICENSE
Normal file
@@ -0,0 +1,674 @@
|
||||
GNU GENERAL PUBLIC LICENSE
|
||||
Version 3, 29 June 2007
|
||||
|
||||
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
Preamble
|
||||
|
||||
The GNU General Public License is a free, copyleft license for
|
||||
software and other kinds of works.
|
||||
|
||||
The licenses for most software and other practical works are designed
|
||||
to take away your freedom to share and change the works. By contrast,
|
||||
the GNU General Public License is intended to guarantee your freedom to
|
||||
share and change all versions of a program--to make sure it remains free
|
||||
software for all its users. We, the Free Software Foundation, use the
|
||||
GNU General Public License for most of our software; it applies also to
|
||||
any other work released this way by its authors. You can apply it to
|
||||
your programs, too.
|
||||
|
||||
When we speak of free software, we are referring to freedom, not
|
||||
price. Our General Public Licenses are designed to make sure that you
|
||||
have the freedom to distribute copies of free software (and charge for
|
||||
them if you wish), that you receive source code or can get it if you
|
||||
want it, that you can change the software or use pieces of it in new
|
||||
free programs, and that you know you can do these things.
|
||||
|
||||
To protect your rights, we need to prevent others from denying you
|
||||
these rights or asking you to surrender the rights. Therefore, you have
|
||||
certain responsibilities if you distribute copies of the software, or if
|
||||
you modify it: responsibilities to respect the freedom of others.
|
||||
|
||||
For example, if you distribute copies of such a program, whether
|
||||
gratis or for a fee, you must pass on to the recipients the same
|
||||
freedoms that you received. You must make sure that they, too, receive
|
||||
or can get the source code. And you must show them these terms so they
|
||||
know their rights.
|
||||
|
||||
Developers that use the GNU GPL protect your rights with two steps:
|
||||
(1) assert copyright on the software, and (2) offer you this License
|
||||
giving you legal permission to copy, distribute and/or modify it.
|
||||
|
||||
For the developers' and authors' protection, the GPL clearly explains
|
||||
that there is no warranty for this free software. For both users' and
|
||||
authors' sake, the GPL requires that modified versions be marked as
|
||||
changed, so that their problems will not be attributed erroneously to
|
||||
authors of previous versions.
|
||||
|
||||
Some devices are designed to deny users access to install or run
|
||||
modified versions of the software inside them, although the manufacturer
|
||||
can do so. This is fundamentally incompatible with the aim of
|
||||
protecting users' freedom to change the software. The systematic
|
||||
pattern of such abuse occurs in the area of products for individuals to
|
||||
use, which is precisely where it is most unacceptable. Therefore, we
|
||||
have designed this version of the GPL to prohibit the practice for those
|
||||
products. If such problems arise substantially in other domains, we
|
||||
stand ready to extend this provision to those domains in future versions
|
||||
of the GPL, as needed to protect the freedom of users.
|
||||
|
||||
Finally, every program is threatened constantly by software patents.
|
||||
States should not allow patents to restrict development and use of
|
||||
software on general-purpose computers, but in those that do, we wish to
|
||||
avoid the special danger that patents applied to a free program could
|
||||
make it effectively proprietary. To prevent this, the GPL assures that
|
||||
patents cannot be used to render the program non-free.
|
||||
|
||||
The precise terms and conditions for copying, distribution and
|
||||
modification follow.
|
||||
|
||||
TERMS AND CONDITIONS
|
||||
|
||||
0. Definitions.
|
||||
|
||||
"This License" refers to version 3 of the GNU General Public License.
|
||||
|
||||
"Copyright" also means copyright-like laws that apply to other kinds of
|
||||
works, such as semiconductor masks.
|
||||
|
||||
"The Program" refers to any copyrightable work licensed under this
|
||||
License. Each licensee is addressed as "you". "Licensees" and
|
||||
"recipients" may be individuals or organizations.
|
||||
|
||||
To "modify" a work means to copy from or adapt all or part of the work
|
||||
in a fashion requiring copyright permission, other than the making of an
|
||||
exact copy. The resulting work is called a "modified version" of the
|
||||
earlier work or a work "based on" the earlier work.
|
||||
|
||||
A "covered work" means either the unmodified Program or a work based
|
||||
on the Program.
|
||||
|
||||
To "propagate" a work means to do anything with it that, without
|
||||
permission, would make you directly or secondarily liable for
|
||||
infringement under applicable copyright law, except executing it on a
|
||||
computer or modifying a private copy. Propagation includes copying,
|
||||
distribution (with or without modification), making available to the
|
||||
public, and in some countries other activities as well.
|
||||
|
||||
To "convey" a work means any kind of propagation that enables other
|
||||
parties to make or receive copies. Mere interaction with a user through
|
||||
a computer network, with no transfer of a copy, is not conveying.
|
||||
|
||||
An interactive user interface displays "Appropriate Legal Notices"
|
||||
to the extent that it includes a convenient and prominently visible
|
||||
feature that (1) displays an appropriate copyright notice, and (2)
|
||||
tells the user that there is no warranty for the work (except to the
|
||||
extent that warranties are provided), that licensees may convey the
|
||||
work under this License, and how to view a copy of this License. If
|
||||
the interface presents a list of user commands or options, such as a
|
||||
menu, a prominent item in the list meets this criterion.
|
||||
|
||||
1. Source Code.
|
||||
|
||||
The "source code" for a work means the preferred form of the work
|
||||
for making modifications to it. "Object code" means any non-source
|
||||
form of a work.
|
||||
|
||||
A "Standard Interface" means an interface that either is an official
|
||||
standard defined by a recognized standards body, or, in the case of
|
||||
interfaces specified for a particular programming language, one that
|
||||
is widely used among developers working in that language.
|
||||
|
||||
The "System Libraries" of an executable work include anything, other
|
||||
than the work as a whole, that (a) is included in the normal form of
|
||||
packaging a Major Component, but which is not part of that Major
|
||||
Component, and (b) serves only to enable use of the work with that
|
||||
Major Component, or to implement a Standard Interface for which an
|
||||
implementation is available to the public in source code form. A
|
||||
"Major Component", in this context, means a major essential component
|
||||
(kernel, window system, and so on) of the specific operating system
|
||||
(if any) on which the executable work runs, or a compiler used to
|
||||
produce the work, or an object code interpreter used to run it.
|
||||
|
||||
The "Corresponding Source" for a work in object code form means all
|
||||
the source code needed to generate, install, and (for an executable
|
||||
work) run the object code and to modify the work, including scripts to
|
||||
control those activities. However, it does not include the work's
|
||||
System Libraries, or general-purpose tools or generally available free
|
||||
programs which are used unmodified in performing those activities but
|
||||
which are not part of the work. For example, Corresponding Source
|
||||
includes interface definition files associated with source files for
|
||||
the work, and the source code for shared libraries and dynamically
|
||||
linked subprograms that the work is specifically designed to require,
|
||||
such as by intimate data communication or control flow between those
|
||||
subprograms and other parts of the work.
|
||||
|
||||
The Corresponding Source need not include anything that users
|
||||
can regenerate automatically from other parts of the Corresponding
|
||||
Source.
|
||||
|
||||
The Corresponding Source for a work in source code form is that
|
||||
same work.
|
||||
|
||||
2. Basic Permissions.
|
||||
|
||||
All rights granted under this License are granted for the term of
|
||||
copyright on the Program, and are irrevocable provided the stated
|
||||
conditions are met. This License explicitly affirms your unlimited
|
||||
permission to run the unmodified Program. The output from running a
|
||||
covered work is covered by this License only if the output, given its
|
||||
content, constitutes a covered work. This License acknowledges your
|
||||
rights of fair use or other equivalent, as provided by copyright law.
|
||||
|
||||
You may make, run and propagate covered works that you do not
|
||||
convey, without conditions so long as your license otherwise remains
|
||||
in force. You may convey covered works to others for the sole purpose
|
||||
of having them make modifications exclusively for you, or provide you
|
||||
with facilities for running those works, provided that you comply with
|
||||
the terms of this License in conveying all material for which you do
|
||||
not control copyright. Those thus making or running the covered works
|
||||
for you must do so exclusively on your behalf, under your direction
|
||||
and control, on terms that prohibit them from making any copies of
|
||||
your copyrighted material outside their relationship with you.
|
||||
|
||||
Conveying under any other circumstances is permitted solely under
|
||||
the conditions stated below. Sublicensing is not allowed; section 10
|
||||
makes it unnecessary.
|
||||
|
||||
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
|
||||
|
||||
No covered work shall be deemed part of an effective technological
|
||||
measure under any applicable law fulfilling obligations under article
|
||||
11 of the WIPO copyright treaty adopted on 20 December 1996, or
|
||||
similar laws prohibiting or restricting circumvention of such
|
||||
measures.
|
||||
|
||||
When you convey a covered work, you waive any legal power to forbid
|
||||
circumvention of technological measures to the extent such circumvention
|
||||
is effected by exercising rights under this License with respect to
|
||||
the covered work, and you disclaim any intention to limit operation or
|
||||
modification of the work as a means of enforcing, against the work's
|
||||
users, your or third parties' legal rights to forbid circumvention of
|
||||
technological measures.
|
||||
|
||||
4. Conveying Verbatim Copies.
|
||||
|
||||
You may convey verbatim copies of the Program's source code as you
|
||||
receive it, in any medium, provided that you conspicuously and
|
||||
appropriately publish on each copy an appropriate copyright notice;
|
||||
keep intact all notices stating that this License and any
|
||||
non-permissive terms added in accord with section 7 apply to the code;
|
||||
keep intact all notices of the absence of any warranty; and give all
|
||||
recipients a copy of this License along with the Program.
|
||||
|
||||
You may charge any price or no price for each copy that you convey,
|
||||
and you may offer support or warranty protection for a fee.
|
||||
|
||||
5. Conveying Modified Source Versions.
|
||||
|
||||
You may convey a work based on the Program, or the modifications to
|
||||
produce it from the Program, in the form of source code under the
|
||||
terms of section 4, provided that you also meet all of these conditions:
|
||||
|
||||
a) The work must carry prominent notices stating that you modified
|
||||
it, and giving a relevant date.
|
||||
|
||||
b) The work must carry prominent notices stating that it is
|
||||
released under this License and any conditions added under section
|
||||
7. This requirement modifies the requirement in section 4 to
|
||||
"keep intact all notices".
|
||||
|
||||
c) You must license the entire work, as a whole, under this
|
||||
License to anyone who comes into possession of a copy. This
|
||||
License will therefore apply, along with any applicable section 7
|
||||
additional terms, to the whole of the work, and all its parts,
|
||||
regardless of how they are packaged. This License gives no
|
||||
permission to license the work in any other way, but it does not
|
||||
invalidate such permission if you have separately received it.
|
||||
|
||||
d) If the work has interactive user interfaces, each must display
|
||||
Appropriate Legal Notices; however, if the Program has interactive
|
||||
interfaces that do not display Appropriate Legal Notices, your
|
||||
work need not make them do so.
|
||||
|
||||
A compilation of a covered work with other separate and independent
|
||||
works, which are not by their nature extensions of the covered work,
|
||||
and which are not combined with it such as to form a larger program,
|
||||
in or on a volume of a storage or distribution medium, is called an
|
||||
"aggregate" if the compilation and its resulting copyright are not
|
||||
used to limit the access or legal rights of the compilation's users
|
||||
beyond what the individual works permit. Inclusion of a covered work
|
||||
in an aggregate does not cause this License to apply to the other
|
||||
parts of the aggregate.
|
||||
|
||||
6. Conveying Non-Source Forms.
|
||||
|
||||
You may convey a covered work in object code form under the terms
|
||||
of sections 4 and 5, provided that you also convey the
|
||||
machine-readable Corresponding Source under the terms of this License,
|
||||
in one of these ways:
|
||||
|
||||
a) Convey the object code in, or embodied in, a physical product
|
||||
(including a physical distribution medium), accompanied by the
|
||||
Corresponding Source fixed on a durable physical medium
|
||||
customarily used for software interchange.
|
||||
|
||||
b) Convey the object code in, or embodied in, a physical product
|
||||
(including a physical distribution medium), accompanied by a
|
||||
written offer, valid for at least three years and valid for as
|
||||
long as you offer spare parts or customer support for that product
|
||||
model, to give anyone who possesses the object code either (1) a
|
||||
copy of the Corresponding Source for all the software in the
|
||||
product that is covered by this License, on a durable physical
|
||||
medium customarily used for software interchange, for a price no
|
||||
more than your reasonable cost of physically performing this
|
||||
conveying of source, or (2) access to copy the
|
||||
Corresponding Source from a network server at no charge.
|
||||
|
||||
c) Convey individual copies of the object code with a copy of the
|
||||
written offer to provide the Corresponding Source. This
|
||||
alternative is allowed only occasionally and noncommercially, and
|
||||
only if you received the object code with such an offer, in accord
|
||||
with subsection 6b.
|
||||
|
||||
d) Convey the object code by offering access from a designated
|
||||
place (gratis or for a charge), and offer equivalent access to the
|
||||
Corresponding Source in the same way through the same place at no
|
||||
further charge. You need not require recipients to copy the
|
||||
Corresponding Source along with the object code. If the place to
|
||||
copy the object code is a network server, the Corresponding Source
|
||||
may be on a different server (operated by you or a third party)
|
||||
that supports equivalent copying facilities, provided you maintain
|
||||
clear directions next to the object code saying where to find the
|
||||
Corresponding Source. Regardless of what server hosts the
|
||||
Corresponding Source, you remain obligated to ensure that it is
|
||||
available for as long as needed to satisfy these requirements.
|
||||
|
||||
e) Convey the object code using peer-to-peer transmission, provided
|
||||
you inform other peers where the object code and Corresponding
|
||||
Source of the work are being offered to the general public at no
|
||||
charge under subsection 6d.
|
||||
|
||||
A separable portion of the object code, whose source code is excluded
|
||||
from the Corresponding Source as a System Library, need not be
|
||||
included in conveying the object code work.
|
||||
|
||||
A "User Product" is either (1) a "consumer product", which means any
|
||||
tangible personal property which is normally used for personal, family,
|
||||
or household purposes, or (2) anything designed or sold for incorporation
|
||||
into a dwelling. In determining whether a product is a consumer product,
|
||||
doubtful cases shall be resolved in favor of coverage. For a particular
|
||||
product received by a particular user, "normally used" refers to a
|
||||
typical or common use of that class of product, regardless of the status
|
||||
of the particular user or of the way in which the particular user
|
||||
actually uses, or expects or is expected to use, the product. A product
|
||||
is a consumer product regardless of whether the product has substantial
|
||||
commercial, industrial or non-consumer uses, unless such uses represent
|
||||
the only significant mode of use of the product.
|
||||
|
||||
"Installation Information" for a User Product means any methods,
|
||||
procedures, authorization keys, or other information required to install
|
||||
and execute modified versions of a covered work in that User Product from
|
||||
a modified version of its Corresponding Source. The information must
|
||||
suffice to ensure that the continued functioning of the modified object
|
||||
code is in no case prevented or interfered with solely because
|
||||
modification has been made.
|
||||
|
||||
If you convey an object code work under this section in, or with, or
|
||||
specifically for use in, a User Product, and the conveying occurs as
|
||||
part of a transaction in which the right of possession and use of the
|
||||
User Product is transferred to the recipient in perpetuity or for a
|
||||
fixed term (regardless of how the transaction is characterized), the
|
||||
Corresponding Source conveyed under this section must be accompanied
|
||||
by the Installation Information. But this requirement does not apply
|
||||
if neither you nor any third party retains the ability to install
|
||||
modified object code on the User Product (for example, the work has
|
||||
been installed in ROM).
|
||||
|
||||
The requirement to provide Installation Information does not include a
|
||||
requirement to continue to provide support service, warranty, or updates
|
||||
for a work that has been modified or installed by the recipient, or for
|
||||
the User Product in which it has been modified or installed. Access to a
|
||||
network may be denied when the modification itself materially and
|
||||
adversely affects the operation of the network or violates the rules and
|
||||
protocols for communication across the network.
|
||||
|
||||
Corresponding Source conveyed, and Installation Information provided,
|
||||
in accord with this section must be in a format that is publicly
|
||||
documented (and with an implementation available to the public in
|
||||
source code form), and must require no special password or key for
|
||||
unpacking, reading or copying.
|
||||
|
||||
7. Additional Terms.
|
||||
|
||||
"Additional permissions" are terms that supplement the terms of this
|
||||
License by making exceptions from one or more of its conditions.
|
||||
Additional permissions that are applicable to the entire Program shall
|
||||
be treated as though they were included in this License, to the extent
|
||||
that they are valid under applicable law. If additional permissions
|
||||
apply only to part of the Program, that part may be used separately
|
||||
under those permissions, but the entire Program remains governed by
|
||||
this License without regard to the additional permissions.
|
||||
|
||||
When you convey a copy of a covered work, you may at your option
|
||||
remove any additional permissions from that copy, or from any part of
|
||||
it. (Additional permissions may be written to require their own
|
||||
removal in certain cases when you modify the work.) You may place
|
||||
additional permissions on material, added by you to a covered work,
|
||||
for which you have or can give appropriate copyright permission.
|
||||
|
||||
Notwithstanding any other provision of this License, for material you
|
||||
add to a covered work, you may (if authorized by the copyright holders of
|
||||
that material) supplement the terms of this License with terms:
|
||||
|
||||
a) Disclaiming warranty or limiting liability differently from the
|
||||
terms of sections 15 and 16 of this License; or
|
||||
|
||||
b) Requiring preservation of specified reasonable legal notices or
|
||||
author attributions in that material or in the Appropriate Legal
|
||||
Notices displayed by works containing it; or
|
||||
|
||||
c) Prohibiting misrepresentation of the origin of that material, or
|
||||
requiring that modified versions of such material be marked in
|
||||
reasonable ways as different from the original version; or
|
||||
|
||||
d) Limiting the use for publicity purposes of names of licensors or
|
||||
authors of the material; or
|
||||
|
||||
e) Declining to grant rights under trademark law for use of some
|
||||
trade names, trademarks, or service marks; or
|
||||
|
||||
f) Requiring indemnification of licensors and authors of that
|
||||
material by anyone who conveys the material (or modified versions of
|
||||
it) with contractual assumptions of liability to the recipient, for
|
||||
any liability that these contractual assumptions directly impose on
|
||||
those licensors and authors.
|
||||
|
||||
All other non-permissive additional terms are considered "further
|
||||
restrictions" within the meaning of section 10. If the Program as you
|
||||
received it, or any part of it, contains a notice stating that it is
|
||||
governed by this License along with a term that is a further
|
||||
restriction, you may remove that term. If a license document contains
|
||||
a further restriction but permits relicensing or conveying under this
|
||||
License, you may add to a covered work material governed by the terms
|
||||
of that license document, provided that the further restriction does
|
||||
not survive such relicensing or conveying.
|
||||
|
||||
If you add terms to a covered work in accord with this section, you
|
||||
must place, in the relevant source files, a statement of the
|
||||
additional terms that apply to those files, or a notice indicating
|
||||
where to find the applicable terms.
|
||||
|
||||
Additional terms, permissive or non-permissive, may be stated in the
|
||||
form of a separately written license, or stated as exceptions;
|
||||
the above requirements apply either way.
|
||||
|
||||
8. Termination.
|
||||
|
||||
You may not propagate or modify a covered work except as expressly
|
||||
provided under this License. Any attempt otherwise to propagate or
|
||||
modify it is void, and will automatically terminate your rights under
|
||||
this License (including any patent licenses granted under the third
|
||||
paragraph of section 11).
|
||||
|
||||
However, if you cease all violation of this License, then your
|
||||
license from a particular copyright holder is reinstated (a)
|
||||
provisionally, unless and until the copyright holder explicitly and
|
||||
finally terminates your license, and (b) permanently, if the copyright
|
||||
holder fails to notify you of the violation by some reasonable means
|
||||
prior to 60 days after the cessation.
|
||||
|
||||
Moreover, your license from a particular copyright holder is
|
||||
reinstated permanently if the copyright holder notifies you of the
|
||||
violation by some reasonable means, this is the first time you have
|
||||
received notice of violation of this License (for any work) from that
|
||||
copyright holder, and you cure the violation prior to 30 days after
|
||||
your receipt of the notice.
|
||||
|
||||
Termination of your rights under this section does not terminate the
|
||||
licenses of parties who have received copies or rights from you under
|
||||
this License. If your rights have been terminated and not permanently
|
||||
reinstated, you do not qualify to receive new licenses for the same
|
||||
material under section 10.
|
||||
|
||||
9. Acceptance Not Required for Having Copies.
|
||||
|
||||
You are not required to accept this License in order to receive or
|
||||
run a copy of the Program. Ancillary propagation of a covered work
|
||||
occurring solely as a consequence of using peer-to-peer transmission
|
||||
to receive a copy likewise does not require acceptance. However,
|
||||
nothing other than this License grants you permission to propagate or
|
||||
modify any covered work. These actions infringe copyright if you do
|
||||
not accept this License. Therefore, by modifying or propagating a
|
||||
covered work, you indicate your acceptance of this License to do so.
|
||||
|
||||
10. Automatic Licensing of Downstream Recipients.
|
||||
|
||||
Each time you convey a covered work, the recipient automatically
|
||||
receives a license from the original licensors, to run, modify and
|
||||
propagate that work, subject to this License. You are not responsible
|
||||
for enforcing compliance by third parties with this License.
|
||||
|
||||
An "entity transaction" is a transaction transferring control of an
|
||||
organization, or substantially all assets of one, or subdividing an
|
||||
organization, or merging organizations. If propagation of a covered
|
||||
work results from an entity transaction, each party to that
|
||||
transaction who receives a copy of the work also receives whatever
|
||||
licenses to the work the party's predecessor in interest had or could
|
||||
give under the previous paragraph, plus a right to possession of the
|
||||
Corresponding Source of the work from the predecessor in interest, if
|
||||
the predecessor has it or can get it with reasonable efforts.
|
||||
|
||||
You may not impose any further restrictions on the exercise of the
|
||||
rights granted or affirmed under this License. For example, you may
|
||||
not impose a license fee, royalty, or other charge for exercise of
|
||||
rights granted under this License, and you may not initiate litigation
|
||||
(including a cross-claim or counterclaim in a lawsuit) alleging that
|
||||
any patent claim is infringed by making, using, selling, offering for
|
||||
sale, or importing the Program or any portion of it.
|
||||
|
||||
11. Patents.
|
||||
|
||||
A "contributor" is a copyright holder who authorizes use under this
|
||||
License of the Program or a work on which the Program is based. The
|
||||
work thus licensed is called the contributor's "contributor version".
|
||||
|
||||
A contributor's "essential patent claims" are all patent claims
|
||||
owned or controlled by the contributor, whether already acquired or
|
||||
hereafter acquired, that would be infringed by some manner, permitted
|
||||
by this License, of making, using, or selling its contributor version,
|
||||
but do not include claims that would be infringed only as a
|
||||
consequence of further modification of the contributor version. For
|
||||
purposes of this definition, "control" includes the right to grant
|
||||
patent sublicenses in a manner consistent with the requirements of
|
||||
this License.
|
||||
|
||||
Each contributor grants you a non-exclusive, worldwide, royalty-free
|
||||
patent license under the contributor's essential patent claims, to
|
||||
make, use, sell, offer for sale, import and otherwise run, modify and
|
||||
propagate the contents of its contributor version.
|
||||
|
||||
In the following three paragraphs, a "patent license" is any express
|
||||
agreement or commitment, however denominated, not to enforce a patent
|
||||
(such as an express permission to practice a patent or covenant not to
|
||||
sue for patent infringement). To "grant" such a patent license to a
|
||||
party means to make such an agreement or commitment not to enforce a
|
||||
patent against the party.
|
||||
|
||||
If you convey a covered work, knowingly relying on a patent license,
|
||||
and the Corresponding Source of the work is not available for anyone
|
||||
to copy, free of charge and under the terms of this License, through a
|
||||
publicly available network server or other readily accessible means,
|
||||
then you must either (1) cause the Corresponding Source to be so
|
||||
available, or (2) arrange to deprive yourself of the benefit of the
|
||||
patent license for this particular work, or (3) arrange, in a manner
|
||||
consistent with the requirements of this License, to extend the patent
|
||||
license to downstream recipients. "Knowingly relying" means you have
|
||||
actual knowledge that, but for the patent license, your conveying the
|
||||
covered work in a country, or your recipient's use of the covered work
|
||||
in a country, would infringe one or more identifiable patents in that
|
||||
country that you have reason to believe are valid.
|
||||
|
||||
If, pursuant to or in connection with a single transaction or
|
||||
arrangement, you convey, or propagate by procuring conveyance of, a
|
||||
covered work, and grant a patent license to some of the parties
|
||||
receiving the covered work authorizing them to use, propagate, modify
|
||||
or convey a specific copy of the covered work, then the patent license
|
||||
you grant is automatically extended to all recipients of the covered
|
||||
work and works based on it.
|
||||
|
||||
A patent license is "discriminatory" if it does not include within
|
||||
the scope of its coverage, prohibits the exercise of, or is
|
||||
conditioned on the non-exercise of one or more of the rights that are
|
||||
specifically granted under this License. You may not convey a covered
|
||||
work if you are a party to an arrangement with a third party that is
|
||||
in the business of distributing software, under which you make payment
|
||||
to the third party based on the extent of your activity of conveying
|
||||
the work, and under which the third party grants, to any of the
|
||||
parties who would receive the covered work from you, a discriminatory
|
||||
patent license (a) in connection with copies of the covered work
|
||||
conveyed by you (or copies made from those copies), or (b) primarily
|
||||
for and in connection with specific products or compilations that
|
||||
contain the covered work, unless you entered into that arrangement,
|
||||
or that patent license was granted, prior to 28 March 2007.
|
||||
|
||||
Nothing in this License shall be construed as excluding or limiting
|
||||
any implied license or other defenses to infringement that may
|
||||
otherwise be available to you under applicable patent law.
|
||||
|
||||
12. No Surrender of Others' Freedom.
|
||||
|
||||
If conditions are imposed on you (whether by court order, agreement or
|
||||
otherwise) that contradict the conditions of this License, they do not
|
||||
excuse you from the conditions of this License. If you cannot convey a
|
||||
covered work so as to satisfy simultaneously your obligations under this
|
||||
License and any other pertinent obligations, then as a consequence you may
|
||||
not convey it at all. For example, if you agree to terms that obligate you
|
||||
to collect a royalty for further conveying from those to whom you convey
|
||||
the Program, the only way you could satisfy both those terms and this
|
||||
License would be to refrain entirely from conveying the Program.
|
||||
|
||||
13. Use with the GNU Affero General Public License.
|
||||
|
||||
Notwithstanding any other provision of this License, you have
|
||||
permission to link or combine any covered work with a work licensed
|
||||
under version 3 of the GNU Affero General Public License into a single
|
||||
combined work, and to convey the resulting work. The terms of this
|
||||
License will continue to apply to the part which is the covered work,
|
||||
but the special requirements of the GNU Affero General Public License,
|
||||
section 13, concerning interaction through a network will apply to the
|
||||
combination as such.
|
||||
|
||||
14. Revised Versions of this License.
|
||||
|
||||
The Free Software Foundation may publish revised and/or new versions of
|
||||
the GNU General Public License from time to time. Such new versions will
|
||||
be similar in spirit to the present version, but may differ in detail to
|
||||
address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the
|
||||
Program specifies that a certain numbered version of the GNU General
|
||||
Public License "or any later version" applies to it, you have the
|
||||
option of following the terms and conditions either of that numbered
|
||||
version or of any later version published by the Free Software
|
||||
Foundation. If the Program does not specify a version number of the
|
||||
GNU General Public License, you may choose any version ever published
|
||||
by the Free Software Foundation.
|
||||
|
||||
If the Program specifies that a proxy can decide which future
|
||||
versions of the GNU General Public License can be used, that proxy's
|
||||
public statement of acceptance of a version permanently authorizes you
|
||||
to choose that version for the Program.
|
||||
|
||||
Later license versions may give you additional or different
|
||||
permissions. However, no additional obligations are imposed on any
|
||||
author or copyright holder as a result of your choosing to follow a
|
||||
later version.
|
||||
|
||||
15. Disclaimer of Warranty.
|
||||
|
||||
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
|
||||
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
|
||||
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
|
||||
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
|
||||
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
|
||||
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
|
||||
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
||||
|
||||
16. Limitation of Liability.
|
||||
|
||||
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
|
||||
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
|
||||
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
|
||||
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
|
||||
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
|
||||
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
|
||||
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
|
||||
SUCH DAMAGES.
|
||||
|
||||
17. Interpretation of Sections 15 and 16.
|
||||
|
||||
If the disclaimer of warranty and limitation of liability provided
|
||||
above cannot be given local legal effect according to their terms,
|
||||
reviewing courts shall apply local law that most closely approximates
|
||||
an absolute waiver of all civil liability in connection with the
|
||||
Program, unless a warranty or assumption of liability accompanies a
|
||||
copy of the Program in return for a fee.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
How to Apply These Terms to Your New Programs
|
||||
|
||||
If you develop a new program, and you want it to be of the greatest
|
||||
possible use to the public, the best way to achieve this is to make it
|
||||
free software which everyone can redistribute and change under these terms.
|
||||
|
||||
To do so, attach the following notices to the program. It is safest
|
||||
to attach them to the start of each source file to most effectively
|
||||
state the exclusion of warranty; and each file should have at least
|
||||
the "copyright" line and a pointer to where the full notice is found.
|
||||
|
||||
<one line to give the program's name and a brief idea of what it does.>
|
||||
Copyright (C) <year> <name of author>
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
If the program does terminal interaction, make it output a short
|
||||
notice like this when it starts in an interactive mode:
|
||||
|
||||
{{ project }} Copyright (C) {{ year }} {{ organization }}
|
||||
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
||||
This is free software, and you are welcome to redistribute it
|
||||
under certain conditions; type `show c' for details.
|
||||
|
||||
The hypothetical commands `show w' and `show c' should show the appropriate
|
||||
parts of the General Public License. Of course, your program's commands
|
||||
might be different; for a GUI interface, you would use an "about box".
|
||||
|
||||
You should also get your employer (if you work as a programmer) or school,
|
||||
if any, to sign a "copyright disclaimer" for the program, if necessary.
|
||||
For more information on this, and how to apply and follow the GNU GPL, see
|
||||
<http://www.gnu.org/licenses/>.
|
||||
|
||||
The GNU General Public License does not permit incorporating your program
|
||||
into proprietary programs. If your program is a subroutine library, you
|
||||
may consider it more useful to permit linking proprietary applications with
|
||||
the library. If this is what you want to do, use the GNU Lesser General
|
||||
Public License instead of this License. But first, please read
|
||||
<http://www.gnu.org/philosophy/why-not-lgpl.html>.
|
53
README.md
53
README.md
@@ -1,16 +1,35 @@
|
||||
# Uploader to automate the Upload and Import of Objects in museum-digital via WebDAV
|
||||
|
||||
The purpose of this app will be to allow museums to more simply automate the upload of
|
||||
their collection data to museum-digital. It is thus targetted at museums using museum-digital
|
||||
their collection data to museum-digital. It is thus targeted at museums using museum-digital
|
||||
as a publication platform, while using another collection management system.
|
||||
|
||||
While collection management systems differ, an automatic import to museum-digital works in
|
||||
a uniform way. Import data is uploaded via WebDAV, an import is configured using a text file. ([See here](https://de.handbook.museum-digital.info/import/importe-selbst-durchfuehren.html))
|
||||
a uniform way. Import data is uploaded via WebDAV, an import is configured using a text file.
|
||||
([See here](https://de.handbook.museum-digital.info/import/importe-selbst-durchfuehren.html))
|
||||
|
||||
This part of the automatic importing can thus be solved in a one-fits-all solution here.
|
||||
Collection management system-specific export scripts are necessary to present the present
|
||||
app with data to upload. The export itself is thus out of the scope of the tool described here.
|
||||
|
||||
## Idea / Very Short Summary / Use Cases
|
||||
|
||||
### Automatic Publication from Separate Collection Management System
|
||||
|
||||
A museum wants to use museum-digital only for publication, while they use a separate collection
|
||||
management system. They want to keep their published collections up to date with their local data.
|
||||
Hence, they automate an export from their local program. To upload, they move the data into a
|
||||
specified folder. The present application monitors the folder and uploads the data to museum-digital.
|
||||
|
||||
### Automating Image Uploads
|
||||
|
||||
If a museum produces a lot of digital media files (e.g. lots of scans of books / manuscripts),
|
||||
it may become tedious to upload them manually. This becomes an issue all the more if there are
|
||||
lots of uncompressed, high resolution files (again, common with scans).
|
||||
In this case, it may be useful to use this application to automatically upload the object images
|
||||
for import using the `ImageByImport` parser - a.k.a. the matching of image files to objects based
|
||||
on their file name according to pre-defined rules.
|
||||
|
||||
## Workflow
|
||||
|
||||
### Setup
|
||||
@@ -26,8 +45,7 @@ It will hence attempt to do so when first run (or unless all relevant informatio
|
||||
- Auth token for WebDAV access
|
||||
- Institution ID
|
||||
- Parser
|
||||
- Location of metadata files to upload
|
||||
- Location of images files to upload
|
||||
- Location of uploadable files
|
||||
- Decision, whether objects should be imported as public
|
||||
|
||||
#### Setup workflow
|
||||
@@ -63,30 +81,11 @@ It will hence attempt to do so when first run (or unless all relevant informatio
|
||||
|
||||
## Commands
|
||||
|
||||
- [ ] Upload
|
||||
- [ ] Verify ability to connect
|
||||
- [ ] Set optional setting (do the settings need to be validated?)
|
||||
- [ ] List config
|
||||
- [ ] Remove optional setting (in case an erroneous setting value has been set)
|
||||
- [ ] `--version` command to check currently installed version
|
||||
- [ ] Version check (via Gitea release RSS feed)
|
||||
See `--help`.
|
||||
|
||||
## Interface
|
||||
|
||||
- A command line interface is sufficient for this application
|
||||
|
||||
## Libraries/resources to include
|
||||
|
||||
- `requests` / HTTP library
|
||||
- JSON parser
|
||||
- XML parser (for version/update check)
|
||||
- WebDAV client: [Python](https://pypi.org/project/webdav4/), [Golang](https://github.com/studio-b12/gowebdav)
|
||||
|
||||
Either JSON or XML may also serve to store the config data.
|
||||
|
||||
## Additional, optional features
|
||||
|
||||
- Multilinguality
|
||||
This application comes with both a web-based UI and a command line interface.
|
||||
|
||||
## Requirements
|
||||
|
||||
@@ -145,3 +144,7 @@ need for an additional connector.
|
||||
#### MuseumPlus
|
||||
|
||||
- Current Version has an API, a connection to it could be built upon that.
|
||||
|
||||
## License
|
||||
|
||||
This source code is licensed under the [GNU General Public License v3](./LICENSE).
|
||||
|
10
go.mod
10
go.mod
@@ -1,3 +1,13 @@
|
||||
module gitea.armuli.eu/museum-digital/museum-digital-webdav-uploader
|
||||
|
||||
go 1.24.0
|
||||
|
||||
require (
|
||||
github.com/go-co-op/gocron/v2 v2.16.0 // indirect
|
||||
github.com/google/uuid v1.6.0 // indirect
|
||||
github.com/jonboulle/clockwork v0.5.0 // indirect
|
||||
github.com/madflojo/tasks v1.2.1 // indirect
|
||||
github.com/robfig/cron/v3 v3.0.1 // indirect
|
||||
github.com/rs/xid v1.6.0 // indirect
|
||||
github.com/studio-b12/gowebdav v0.10.0 // indirect
|
||||
)
|
||||
|
12
go.sum
Normal file
12
go.sum
Normal file
@@ -0,0 +1,12 @@
|
||||
github.com/go-co-op/gocron/v2 v2.16.0 h1:uqUF6WFZ4enRU45pWFNcn1xpDLc+jBOTKhPQI16Z1xs=
|
||||
github.com/go-co-op/gocron/v2 v2.16.0/go.mod h1:opexeOFy5BplhsKdA7bzY9zeYih8I8/WNJ4arTIFPVc=
|
||||
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
|
||||
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
||||
github.com/jonboulle/clockwork v0.5.0 h1:Hyh9A8u51kptdkR+cqRpT1EebBwTn1oK9YfGYbdFz6I=
|
||||
github.com/jonboulle/clockwork v0.5.0/go.mod h1:3mZlmanh0g2NDKO5TWZVJAfofYk64M7XN3SzBPjZF60=
|
||||
github.com/madflojo/tasks v1.2.1/go.mod h1:/WMv6u3Xb5eyy+aIM76ildaIT166GOxN/jya9oI7dyo=
|
||||
github.com/robfig/cron/v3 v3.0.1 h1:WdRxkvbJztn8LMz/QEvLN5sBU+xKpSqwwUO1Pjr4qDs=
|
||||
github.com/robfig/cron/v3 v3.0.1/go.mod h1:eQICP3HwyT7UooqI/z+Ov+PtYAWygg1TEWWzGIFLtro=
|
||||
github.com/rs/xid v1.6.0/go.mod h1:7XoLgs4eV+QndskICGsho+ADou8ySMSjJKDIan90Nz0=
|
||||
github.com/studio-b12/gowebdav v0.10.0 h1:Yewz8FFiadcGEu4hxS/AAJQlHelndqln1bns3hcJIYc=
|
||||
github.com/studio-b12/gowebdav v0.10.0/go.mod h1:bHA7t77X/QFExdeAnDzK6vKM34kEZAcE1OX4MfiwjkE=
|
67
main.go
67
main.go
@@ -1,38 +1,43 @@
|
||||
package main
|
||||
|
||||
import "fmt"
|
||||
import (
|
||||
"gitea.armuli.eu/museum-digital/museum-digital-webdav-uploader/src/configLoader"
|
||||
"gitea.armuli.eu/museum-digital/museum-digital-webdav-uploader/src/setup"
|
||||
"slices"
|
||||
"os"
|
||||
"gitea.armuli.eu/museum-digital/museum-digital-webdav-uploader/src/cli"
|
||||
"gitea.armuli.eu/museum-digital/museum-digital-webdav-uploader/src/webui"
|
||||
)
|
||||
|
||||
// Attempts to connect to WebDAV server, verifying that the authentication data
|
||||
// works and that the server is one for uploads with museum-digital.
|
||||
// A museum-digital WebDAV directory can be identified by the availability of the
|
||||
// directories IMPORT_IMG and IMPORT_XML.
|
||||
func verifyConnection(config MDWebDavUploaderConfig) bool {
|
||||
|
||||
}
|
||||
|
||||
// Generates the contents of the file import_config.txt necessary
|
||||
// to let museum-digital know about the required import configuration.
|
||||
func generateImportConfigFile() string {
|
||||
|
||||
}
|
||||
|
||||
|
||||
// Uploads metadata files to the configured instance of
|
||||
// museum-digital / musdb.
|
||||
func uploadMetadataFiles() {
|
||||
|
||||
}
|
||||
|
||||
// Uploads media files to the configured instance of
|
||||
// museum-digital / musdb.
|
||||
func uploadMediaFiles() {
|
||||
|
||||
}
|
||||
|
||||
// Negotiates commands based on command line options.
|
||||
func main() {
|
||||
fmt.Println("hi")
|
||||
|
||||
if slices.Contains(os.Args, "--help") {
|
||||
cli.ShowHelpText();
|
||||
} else if slices.Contains(os.Args, "--version") {
|
||||
cli.ShowVersion();
|
||||
} else if slices.Contains(os.Args, "--check-update") {
|
||||
cli.CheckVersionIsUpToDate();
|
||||
} else if slices.Contains(os.Args, "--show-config") {
|
||||
cli.ShowCurrentConfig()
|
||||
} else if slices.Contains(os.Args, "--run-manual-setup") {
|
||||
cli.RunManualSetup()
|
||||
} else if slices.Contains(os.Args, "--set-additional-setting") {
|
||||
cli.SetAdditionalSetting()
|
||||
} else if slices.Contains(os.Args, "--upload") {
|
||||
cli.Upload()
|
||||
} else if slices.Contains(os.Args, "--webdav-remote-list-toplevel") {
|
||||
cli.ListRemoteToplevel()
|
||||
} else if slices.Contains(os.Args, "--webdav-remote-list-metadata-dir") {
|
||||
cli.ListRemoteMetadataDir()
|
||||
} else if slices.Contains(os.Args, "--webdav-remote-list-media-dir") {
|
||||
cli.ListRemoteMediaDir()
|
||||
} else if slices.Contains(os.Args, "--local-list-metadata") {
|
||||
cli.ListLocalMetadata()
|
||||
} else if slices.Contains(os.Args, "--local-list-media") {
|
||||
cli.ListLocalMedia()
|
||||
} else if slices.Contains(os.Args, "--webui") {
|
||||
webui.Run()
|
||||
} else {
|
||||
webui.Run()
|
||||
}
|
||||
|
||||
}
|
||||
|
22
makefile
Normal file
22
makefile
Normal file
@@ -0,0 +1,22 @@
|
||||
VERSION := $(shell go run main.go --version)
|
||||
|
||||
hello:
|
||||
echo WebDAV uploader for museum-digital
|
||||
echo Version is $(VERSION)
|
||||
|
||||
build:
|
||||
go build -o bin/museum-digital-webdav-uploader main.go
|
||||
|
||||
run:
|
||||
go run main.go
|
||||
|
||||
compile:
|
||||
echo "Compiling for every OS and Platform"
|
||||
GOOS=linux GOARCH=amd64 go build -o bin/museum-digital-webdav-uploader-$(VERSION)-linux-amd64 main.go
|
||||
GOOS=windows GOARCH=amd64 go build -o bin/museum-digital-webdav-uploader-$(VERSION)-windows-amd64.exe main.go
|
||||
GOOS=darwin GOARCH=amd64 go build -o bin/museum-digital-webdav-uploader-$(VERSION)-macos-amd64 main.go
|
||||
GOOS=linux GOARCH=arm64 go build -o bin/museum-digital-webdav-uploader-$(VERSION)-linux-arm64 main.go
|
||||
GOOS=windows GOARCH=arm64 go build -o bin/museum-digital-webdav-uploader-$(VERSION)-windows-arm64.exe main.go
|
||||
GOOS=darwin GOARCH=arm64 go build -o bin/museum-digital-webdav-uploader-$(VERSION)-macos-arm64 main.go
|
||||
|
||||
all: hello build
|
32
src/cli/ShowHelpText.go
Normal file
32
src/cli/ShowHelpText.go
Normal file
@@ -0,0 +1,32 @@
|
||||
package cli
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
)
|
||||
|
||||
func ShowHelpText() {
|
||||
|
||||
fmt.Println(`museum-digital uploader
|
||||
|
||||
A tool to manage the configuration of imports to museum-digital and simplify the upload process.
|
||||
|
||||
Commands:
|
||||
|
||||
(no command), --webui Runs a small dashboard and opens a browser to view it.
|
||||
Use this for using the app without the command line.
|
||||
--show-config Show current config in JSON format.
|
||||
--run-manual-setup Opens a CLI-based settings dialogue.
|
||||
--set-additional-setting Allows setting optional, parser-specific settings.
|
||||
--upload Upload data for import.
|
||||
--webdav-remote-list-toplevel Show folder contents of the WebDAV share used for imports.
|
||||
--webdav-remote-list-metadata-dir Show folder contents of the WebDAV share used for imports (metadata subdirectory).
|
||||
--webdav-remote-list-media-dir Show folder contents of the WebDAV share used for imports (media subdirectory).
|
||||
--local-list-metadata Lists metadata files currently present in the upload directory.
|
||||
--local-list-media Lists media files currently present in the upload directory.
|
||||
--help Print help message.
|
||||
--check-update Check for updates to this application.
|
||||
|
||||
Links:
|
||||
Source code: https://gitea.armuli.eu/museum-digital/museum-digital-webdav-uploader`)
|
||||
|
||||
}
|
11
src/cli/ShowVersion.go
Normal file
11
src/cli/ShowVersion.go
Normal file
@@ -0,0 +1,11 @@
|
||||
package cli
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"gitea.armuli.eu/museum-digital/museum-digital-webdav-uploader/src/meta"
|
||||
)
|
||||
|
||||
// Prints current version.
|
||||
func ShowVersion() {
|
||||
fmt.Println(meta.GetVersion())
|
||||
}
|
53
src/cli/Upload.go
Normal file
53
src/cli/Upload.go
Normal file
@@ -0,0 +1,53 @@
|
||||
package cli
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"gitea.armuli.eu/museum-digital/museum-digital-webdav-uploader/src/uploadsrcdir"
|
||||
"gitea.armuli.eu/museum-digital/museum-digital-webdav-uploader/src/webdavupload"
|
||||
)
|
||||
|
||||
// Integration: Uploads, if there is uploadable data and no import currently
|
||||
// scheduled.
|
||||
func Upload() {
|
||||
|
||||
config := loadConfigFromFile()
|
||||
uploadableMetadata, uploadableMedia := uploadsrcdir.GetUploadableFiles(config)
|
||||
|
||||
// If there are no files to upload, do nothing
|
||||
if len(uploadableMetadata) == 0 && len(uploadableMedia) == 0 {
|
||||
fmt.Println("No uploadable files identified.")
|
||||
return
|
||||
}
|
||||
|
||||
// Ensure no files are too new too recent - if any are, say so and abort.
|
||||
if uploadsrcdir.CheckAnyFileIsTooRecent(uploadableMedia) || uploadsrcdir.CheckAnyFileIsTooRecent(uploadableMetadata) {
|
||||
fmt.Println("Some of the files have been updated too recently (1min). Blocking upload to prevent accidental uploads in the middle of an ongoing digitization effort.")
|
||||
return
|
||||
}
|
||||
|
||||
// Open WebDAV client
|
||||
c := webdavupload.GetWebdavClient(config)
|
||||
|
||||
// Check that the remote is not currently occupied.
|
||||
if webdavupload.CheckRemoteIsFree(c) == false {
|
||||
fmt.Println("The remote is currently occupied (very recent files, or an import config is currently waiting to be processed, are present).")
|
||||
return
|
||||
}
|
||||
|
||||
// Upload the files
|
||||
if len(uploadableMetadata) > 0 {
|
||||
webdavupload.UploadMetadataFiles(c, os.Stdout, uploadableMetadata)
|
||||
webdavupload.BatchUnlink(os.Stdout, uploadableMetadata)
|
||||
}
|
||||
if len(uploadableMedia) > 0 {
|
||||
webdavupload.UploadMediaFiles(c, os.Stdout, uploadableMedia)
|
||||
webdavupload.BatchUnlink(os.Stdout, uploadableMedia)
|
||||
}
|
||||
|
||||
// Generate the import config.
|
||||
fmt.Println("Generating and uploading import configuration")
|
||||
webdavupload.SetImportConfigToTheRemote(c, config)
|
||||
fmt.Println("DONE")
|
||||
|
||||
}
|
394
src/cli/cli.go
Normal file
394
src/cli/cli.go
Normal file
@@ -0,0 +1,394 @@
|
||||
package cli
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"fmt"
|
||||
"os"
|
||||
"strconv"
|
||||
"strings"
|
||||
"gitea.armuli.eu/museum-digital/museum-digital-webdav-uploader/src/configloader"
|
||||
"gitea.armuli.eu/museum-digital/museum-digital-webdav-uploader/src/uploadsrcdir"
|
||||
"gitea.armuli.eu/museum-digital/museum-digital-webdav-uploader/src/webdavupload"
|
||||
"gitea.armuli.eu/museum-digital/museum-digital-webdav-uploader/src/meta"
|
||||
)
|
||||
|
||||
// Interal wrapper around opening a new bufio.Reader and getting an input
|
||||
// from it. As errors here likely really are something fundamentally wrong
|
||||
// about the system, panic if there is one.
|
||||
func getConsoleInput() string {
|
||||
|
||||
reader := bufio.NewReader(os.Stdin)
|
||||
output, err := reader.ReadString('\n')
|
||||
|
||||
if err != nil {
|
||||
fmt.Println("Failed to get console input!")
|
||||
panic(err)
|
||||
}
|
||||
|
||||
return strings.Trim(output, "\n\r")
|
||||
|
||||
}
|
||||
|
||||
// Prompts the user to enter a valid instance url until they do.
|
||||
func requestInstanceLink() string {
|
||||
|
||||
fmt.Println("\nPlease enter URL of the instance of museum-digital you work in.")
|
||||
fmt.Println("This should be a regional instance (e.g. hessen.museum-digital.de), not an aggregated one like nat.museum-digital.de.")
|
||||
|
||||
input := getConsoleInput()
|
||||
|
||||
output, validationErr := configloader.ValidateInstanceLink(input)
|
||||
if validationErr != nil {
|
||||
fmt.Println("This is not a valid instance of museum-digital / musdb. Please try again.")
|
||||
fmt.Print("----\nThe specific error is:\n")
|
||||
fmt.Println(validationErr)
|
||||
fmt.Print("----\n\n")
|
||||
return requestInstanceLink()
|
||||
}
|
||||
|
||||
return output
|
||||
|
||||
}
|
||||
|
||||
// Prompts the user to enter a valid institution ID within the
|
||||
// specified instance until they do.
|
||||
func requestInstitutionId(instanceLink string) int {
|
||||
|
||||
fmt.Println("\nPlease enter ID of your institution.")
|
||||
fmt.Println("You can find the ID of the institution ID in musdb. On the institution/museum editing page, you will find it as a large number below the orange bar \"museum\".")
|
||||
|
||||
input := getConsoleInput()
|
||||
i, err := strconv.Atoi(input)
|
||||
if err != nil {
|
||||
fmt.Println("You did not enter a number. Please try again.")
|
||||
return requestInstitutionId(instanceLink)
|
||||
}
|
||||
|
||||
output, validationErr := configloader.ValidateInstitutionId(i, instanceLink)
|
||||
if validationErr != nil {
|
||||
fmt.Println("This is not a valid institution ID. Please try again.")
|
||||
fmt.Print("----\nThe specific error is:\n")
|
||||
fmt.Println(validationErr)
|
||||
fmt.Print("----\n\n")
|
||||
return requestInstitutionId(instanceLink)
|
||||
}
|
||||
|
||||
return output
|
||||
|
||||
}
|
||||
|
||||
// Prompts the user to enter their username.
|
||||
func requestUsername() string {
|
||||
|
||||
fmt.Println("\nPlease enter your user name in musdb (the name you use to log in with).")
|
||||
|
||||
input := getConsoleInput()
|
||||
|
||||
if input == "" {
|
||||
fmt.Println("You may not enter an empty user name. Please try again.")
|
||||
return requestUsername()
|
||||
}
|
||||
|
||||
return input
|
||||
|
||||
}
|
||||
|
||||
// Prompts the user to enter a valid mail address until they do.
|
||||
func requestMail() string {
|
||||
|
||||
fmt.Println("\nPlease enter the email you set for your musdb account.")
|
||||
fmt.Println("Note that the spelling needs to be exactly the same as it is entered in musdb (e.g. in terms of capitalization).")
|
||||
|
||||
input := getConsoleInput()
|
||||
|
||||
output, validationErr := configloader.ValidateMail(input)
|
||||
if validationErr != nil {
|
||||
fmt.Println("This is not a valid mail address. Please try again.")
|
||||
fmt.Print("----\nThe specific error is:\n")
|
||||
fmt.Println(validationErr)
|
||||
fmt.Print("----\n\n")
|
||||
return requestMail()
|
||||
}
|
||||
|
||||
return output
|
||||
|
||||
}
|
||||
|
||||
// Prompts the user to enter the webdav auth token.
|
||||
func requestWebDavAuthToken() string {
|
||||
|
||||
fmt.Println("\nPlease enter your WebDAV authentication token.")
|
||||
fmt.Println("You can generate a WebDAV authentication token on your account settings page in the tab \"WebDAV\".")
|
||||
|
||||
input := getConsoleInput()
|
||||
|
||||
if input == "" {
|
||||
fmt.Println("You may not enter an empty WebDAV authentication token. Please try again.")
|
||||
return requestWebDavAuthToken()
|
||||
}
|
||||
|
||||
return input
|
||||
|
||||
}
|
||||
|
||||
// Prompts the user to enter a valid parser name until they do.
|
||||
func requestParser() string {
|
||||
|
||||
fmt.Println("\nPlease enter the parser with which you want to run imports.")
|
||||
fmt.Println("Parsers correspond with the input format. Available parsers are:")
|
||||
|
||||
fmt.Println("")
|
||||
for _, parser := range(configloader.ListParsers()) {
|
||||
fmt.Println("- " + parser.Title)
|
||||
}
|
||||
fmt.Println("")
|
||||
|
||||
input := getConsoleInput()
|
||||
|
||||
output, validationErr := configloader.ValidateParser(input)
|
||||
if validationErr != nil {
|
||||
fmt.Println("This is not a valid parser name. Please enter one from the list. Please try again.")
|
||||
fmt.Print("----\nThe specific error is:\n")
|
||||
fmt.Println(validationErr)
|
||||
fmt.Print("----\n\n")
|
||||
return requestParser()
|
||||
}
|
||||
|
||||
return output
|
||||
|
||||
}
|
||||
|
||||
// Prompts the user to enter a valid folder for uploads.
|
||||
func requestUploadFolder() string {
|
||||
|
||||
fmt.Println("\nPlease enter the full filepath of a directory in which the program should look for files to upload.")
|
||||
fmt.Println("Note that the folder needs to exist.")
|
||||
|
||||
input := getConsoleInput()
|
||||
|
||||
output, validationErr := configloader.ValidateUploadDir(input)
|
||||
if validationErr != nil {
|
||||
fmt.Println("This is not a valid metadata folder. Please try again.")
|
||||
fmt.Print("----\nThe specific error is:\n")
|
||||
fmt.Println(validationErr)
|
||||
fmt.Print("----\n\n")
|
||||
return requestUploadFolder()
|
||||
}
|
||||
|
||||
return output
|
||||
|
||||
}
|
||||
|
||||
// Prompts the user to say, whether they want to immediately publish the uploaded objects once imported.
|
||||
func requestPublishOnImport() bool {
|
||||
|
||||
fmt.Println("\nDo you want to immediately publish your objects, once they have been imported? If so, enter 'y', else, enter 'n'")
|
||||
|
||||
input := getConsoleInput()
|
||||
|
||||
if input == "y" {
|
||||
return true
|
||||
} else if input == "n" {
|
||||
return false
|
||||
} else {
|
||||
fmt.Println("You did not enter either y or n, please try again.")
|
||||
return requestPublishOnImport()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Wrapper around configloader.StoreConfigToFile that prints the error message
|
||||
// if storing failed.
|
||||
func storeConfigToFile(config configloader.MDWebDavUploaderConfig) {
|
||||
|
||||
err := configloader.StoreConfigToFile(config, "")
|
||||
if err != nil {
|
||||
fmt.Println("\nFailed to store config")
|
||||
fmt.Println("Reason:")
|
||||
fmt.Println(err)
|
||||
panic("")
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Queries the user for each of the relevant values for setup.
|
||||
func RunManualSetup() {
|
||||
|
||||
fmt.Println("Welcome to the setup of the museum-digital auto uploader")
|
||||
fmt.Println("This is the fully manual version of the setup, hence you will be asked for each value")
|
||||
|
||||
config := configloader.MDWebDavUploaderConfig{}
|
||||
|
||||
config.InstanceLink = requestInstanceLink()
|
||||
config.Username = requestUsername()
|
||||
config.InstitutionId = requestInstitutionId(config.InstanceLink)
|
||||
config.Mail = requestMail()
|
||||
config.WebDavAuthToken = requestWebDavAuthToken()
|
||||
config.Parser = requestParser()
|
||||
config.UploadDir = requestUploadFolder()
|
||||
config.PublishOnImport = requestPublishOnImport()
|
||||
|
||||
storeConfigToFile(config)
|
||||
|
||||
fmt.Println("Great! Your configuration has been stored. If you need to set further parser-specific settings, use --set-additional-setting. Else, use --upload.")
|
||||
|
||||
}
|
||||
|
||||
// Wrapper around configloader.LoadFromFile() that prints errors.
|
||||
func loadConfigFromFile() configloader.MDWebDavUploaderConfig {
|
||||
|
||||
config, requiresSetup, err := configloader.LoadFromFile("")
|
||||
|
||||
// Re-run manual setup and then load anew.
|
||||
if requiresSetup == true {
|
||||
|
||||
fmt.Println("Your config is incomplete. Please run the setup command before proceeding.")
|
||||
RunManualSetup()
|
||||
config, _, rerunerr := configloader.LoadFromFile("")
|
||||
if rerunerr != nil {
|
||||
fmt.Println("Another error occured in loading your configuration:")
|
||||
fmt.Println(rerunerr)
|
||||
panic("")
|
||||
}
|
||||
return config
|
||||
|
||||
} else if err != nil {
|
||||
fmt.Println("Another error occured in loading your configuration:")
|
||||
fmt.Println(err)
|
||||
panic("")
|
||||
}
|
||||
|
||||
return config
|
||||
|
||||
}
|
||||
|
||||
// Prints the current configuration.
|
||||
func ShowCurrentConfig() {
|
||||
|
||||
config := loadConfigFromFile()
|
||||
fmt.Println(config)
|
||||
|
||||
}
|
||||
|
||||
func SetAdditionalSetting() {
|
||||
|
||||
config := loadConfigFromFile()
|
||||
|
||||
// Welcome msg
|
||||
fmt.Println("You are trying to set an additional setting. For this, you will need to enter 1) which setting you want to manipulate and 2) what you want to set it to.")
|
||||
fmt.Println("-----\n")
|
||||
|
||||
// Print parser-specific settings
|
||||
fmt.Println("Your currently configured parser is: " + config.Parser)
|
||||
fmt.Println("You can learn more about the available settings for this parser in the parser documentation. Printing it now.")
|
||||
|
||||
for _, p := range(configloader.ListParsers()) {
|
||||
if p.Title == config.Parser {
|
||||
fmt.Println(p.Comment)
|
||||
}
|
||||
}
|
||||
|
||||
fmt.Println("\n-----\n")
|
||||
|
||||
// Get values
|
||||
fmt.Println("Now, please enter which setting you would like to manipulate.")
|
||||
settingKey := getConsoleInput()
|
||||
|
||||
fmt.Println("What would you like to set the setting to?")
|
||||
settingValue := getConsoleInput()
|
||||
|
||||
if config.Settings == nil {
|
||||
config.Settings = make(map[string]string)
|
||||
}
|
||||
config.Settings[settingKey] = settingValue
|
||||
|
||||
storeConfigToFile(config)
|
||||
|
||||
}
|
||||
|
||||
// Receives a list of files and an error. If the error exists, that is printed.
|
||||
// Otherwise, the listed files of a directory are listed.
|
||||
func printFolderContents(files []os.FileInfo, err error) {
|
||||
|
||||
if err != nil {
|
||||
fmt.Println("Failed to list top level folder contents")
|
||||
return
|
||||
}
|
||||
|
||||
if len(files) == 0 {
|
||||
fmt.Print("There are no files to print here.\n")
|
||||
}
|
||||
|
||||
for _, f := range(files) {
|
||||
fmt.Println(f.Name())
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Prints the top level folder contents of the WebDAV remote
|
||||
func ListRemoteToplevel() {
|
||||
|
||||
config := loadConfigFromFile()
|
||||
files, err := webdavupload.ListTopLevelContents(config)
|
||||
printFolderContents(files, err)
|
||||
|
||||
}
|
||||
|
||||
// Prints the current contents of the remote metadata directory.
|
||||
func ListRemoteMetadataDir() {
|
||||
|
||||
config := loadConfigFromFile()
|
||||
files, err := webdavupload.ListMetadataDir(config)
|
||||
printFolderContents(files, err)
|
||||
|
||||
}
|
||||
|
||||
// Prints the current contents of the remote media directory.
|
||||
func ListRemoteMediaDir() {
|
||||
|
||||
config := loadConfigFromFile()
|
||||
files, err := webdavupload.ListMediaDir(config)
|
||||
printFolderContents(files, err)
|
||||
|
||||
}
|
||||
|
||||
// Prints the current contents of the local metadata directory.
|
||||
func ListLocalMetadata() {
|
||||
|
||||
fmt.Println("Printing uploadable metadata files")
|
||||
config := loadConfigFromFile()
|
||||
files := uploadsrcdir.ListUploadableMetadata(config)
|
||||
printFolderContents(files, nil)
|
||||
|
||||
}
|
||||
|
||||
// Prints the current contents of the local media directory.
|
||||
func ListLocalMedia() {
|
||||
|
||||
fmt.Println("Printing uploadable media files")
|
||||
config := loadConfigFromFile()
|
||||
files := uploadsrcdir.ListUploadableMedia(config)
|
||||
printFolderContents(files, nil)
|
||||
|
||||
}
|
||||
|
||||
// Prints, if there is a current version.
|
||||
func CheckVersionIsUpToDate() {
|
||||
|
||||
output, err := meta.CheckVersionIsUpToDate()
|
||||
if err != nil {
|
||||
fmt.Println("Failed to get RSS stream for most recent entry")
|
||||
fmt.Print(err)
|
||||
panic("Aborting")
|
||||
}
|
||||
|
||||
// Empty output has no title
|
||||
if output.Title == "" {
|
||||
fmt.Println("Your version is up to date")
|
||||
} else {
|
||||
fmt.Println("There is a more recent version, version: " + output.Title)
|
||||
fmt.Println("\nReleased: " + output.PubDate)
|
||||
fmt.Println("\nGet it at " + output.Link)
|
||||
}
|
||||
|
||||
}
|
28
src/configloader/HttpGetStatusCode.go
Normal file
28
src/configloader/HttpGetStatusCode.go
Normal file
@@ -0,0 +1,28 @@
|
||||
package configloader
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
)
|
||||
|
||||
// Returns the HTTP status code for a url while sending requests using
|
||||
// a user-agent specific to the app.
|
||||
func HttpGetStatusCode(url string) (int, error) {
|
||||
|
||||
// create HTTP request
|
||||
req, err := http.NewRequest("GET", url, nil)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
// set User-Agent header
|
||||
req.Header.Set("User-Agent", "museum-digital-uploader")
|
||||
|
||||
resp, err := http.DefaultClient.Do(req)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
return resp.StatusCode, nil
|
||||
|
||||
}
|
61
src/configloader/ListParsers.go
Normal file
61
src/configloader/ListParsers.go
Normal file
@@ -0,0 +1,61 @@
|
||||
package configloader
|
||||
|
||||
import _ "embed"
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"slices"
|
||||
)
|
||||
|
||||
type ParserListItem struct {
|
||||
Title string `json:"title"`
|
||||
Comment string `json:"comment"`
|
||||
Authors []string `json:"authors"`
|
||||
Links []string `json:"links"`
|
||||
}
|
||||
|
||||
// Load parser list from JSON retrieved from musdb's API
|
||||
// See https://<subdomain>.museum-digital.org/musdb/api/meta/list_import_parsers
|
||||
// The embed module requires the variable to not be bound to a function.
|
||||
|
||||
//go:embed parser_list.json
|
||||
var rawParserList []byte
|
||||
|
||||
// Returns a list of the available parsers.
|
||||
func ListParsers() []ParserListItem {
|
||||
|
||||
parserListFromApi := []ParserListItem{}
|
||||
// parserListFromApi := new(ApiParserListFormat)
|
||||
json.Unmarshal(rawParserList, &parserListFromApi)
|
||||
|
||||
return parserListFromApi
|
||||
|
||||
}
|
||||
|
||||
// Checks if inputParser is in the list of available parsers.
|
||||
// Returns the parser name or an error.
|
||||
func ValidateParser(inputParser string) (string, error) {
|
||||
|
||||
parserList := ListParsers()
|
||||
parserTitles := []string{}
|
||||
|
||||
for _, p := range(parserList) {
|
||||
parserTitles = append(parserTitles, p.Title)
|
||||
}
|
||||
|
||||
if slices.Contains(parserTitles, inputParser) {
|
||||
return inputParser, nil
|
||||
}
|
||||
|
||||
// Accepted invalid modes to clean up:
|
||||
// ParserLido > Lido
|
||||
// lido > Lido
|
||||
cleaned := inputParser[6:]
|
||||
if slices.Contains(parserTitles, cleaned) {
|
||||
return cleaned, nil
|
||||
}
|
||||
|
||||
return "", errors.New("Invalid parser selected")
|
||||
|
||||
}
|
55
src/configloader/ListParsers_test.go
Normal file
55
src/configloader/ListParsers_test.go
Normal file
@@ -0,0 +1,55 @@
|
||||
package configloader
|
||||
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
// Tests that the list of parsers is not empty.
|
||||
func TestListParserReturnsNonEmptyResult(t *testing.T) {
|
||||
|
||||
parserList := ListParsers()
|
||||
if len(parserList) == 0 {
|
||||
t.Fatalf("The list of returned parsers is empty")
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Ensures that validating a parser will not accept an invalid parser name.
|
||||
func TestInvalidParserIsNotAccepted(t *testing.T) {
|
||||
|
||||
parser, err := ValidateParser("Liddasfasdo")
|
||||
if parser != "" {
|
||||
t.Fatalf("ValidateParser() should return an empty string + error")
|
||||
}
|
||||
if err == nil {
|
||||
t.Fatalf("ValidateParser() did not return an error where it should")
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Ensures that a parser is valid at its expected name.
|
||||
func TestValidParserIsAccepted(t *testing.T) {
|
||||
|
||||
parser, err := ValidateParser("Lido")
|
||||
if parser != "Lido" {
|
||||
t.Fatalf("Test expected validated parser for input 'Lido' to be 'Lido'")
|
||||
}
|
||||
if err != nil {
|
||||
t.Fatalf("ValidateParser() returned an error where it should not")
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Prepending the prefix "Parser" to a parser name should work as well.
|
||||
// In this case, the prefix should be removed by ValidateParser().
|
||||
func TestValidParserIsAcceptedAndCleaned(t *testing.T) {
|
||||
|
||||
parser, err := ValidateParser("ParserLido")
|
||||
if parser != "Lido" {
|
||||
t.Fatalf("Test expected validated parser for input 'ParserLido' to be 'Lido'")
|
||||
}
|
||||
if err != nil {
|
||||
t.Fatalf("ValidateParser() returned an error where it should not")
|
||||
}
|
||||
|
||||
}
|
46
src/configloader/ValidateInstanceLink.go
Normal file
46
src/configloader/ValidateInstanceLink.go
Normal file
@@ -0,0 +1,46 @@
|
||||
package configloader
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"net/url"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// Validates a museum-digital instance URL to upload to.
|
||||
// The link must be a valid URL. As it can be expected that people will
|
||||
// enter broken values, the URL should be reduced to its hostname and
|
||||
// rebuilt from there.
|
||||
func ValidateInstanceLink(instanceUrl string) (string, error) {
|
||||
|
||||
parsed, err := url.Parse(instanceUrl)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
// Check the hostname contains "museum-digital.de" or "museum-digital.org"
|
||||
if !strings.HasSuffix(parsed.Host, "museum-digital.de") && !strings.HasSuffix(parsed.Host, "museum-digital.org") {
|
||||
return "", errors.New("This tool only supports uploading to XYZ.museum-digital.de or XYZ.museum-digital.org")
|
||||
}
|
||||
|
||||
// Check /musdb is available on the md instance
|
||||
musdbUrl := url.URL{
|
||||
Scheme: "https",
|
||||
Host: parsed.Host,
|
||||
Path: "/musdb",
|
||||
}
|
||||
statusCode, err := HttpGetStatusCode(musdbUrl.String())
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
if statusCode > 399 {
|
||||
return "", errors.New("The museum-digital subdomain does not contain a musdb path")
|
||||
}
|
||||
|
||||
// https should be assumed and enforced.
|
||||
url := url.URL{
|
||||
Scheme: "https",
|
||||
Host: parsed.Host,
|
||||
}
|
||||
return url.String(), nil
|
||||
|
||||
}
|
69
src/configloader/ValidateInstanceLink_test.go
Normal file
69
src/configloader/ValidateInstanceLink_test.go
Normal file
@@ -0,0 +1,69 @@
|
||||
package configloader
|
||||
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
// Test that ValidateInstanceLink() fails on non-URLs.
|
||||
func TestValidateInstanceFailsOnNonUrl(t *testing.T) {
|
||||
|
||||
_, err := ValidateInstanceLink("abcmuseum-digital.org")
|
||||
|
||||
if err == nil {
|
||||
t.Fatalf("ValidateInstanceLink() does not return an error on a non-URL")
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Test that ValidateInstanceLink() fails on links outside of md.
|
||||
func TestValidateInstanceLinkFailsOutsideOfMd(t *testing.T) {
|
||||
|
||||
_, err := ValidateInstanceLink("test.museum-digital.de")
|
||||
|
||||
if err == nil {
|
||||
t.Fatalf("ValidateInstanceLink() accepts URLs outside of the main museum-digital")
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Test that ValidateInstanceLink() fails on valid md aggregated instances
|
||||
// (uploads can only happen to regional instances / those that have a dedicated
|
||||
// instance of musdb).
|
||||
func TestValidateInstanceLinkFailsWithAggregatedInstance(t *testing.T) {
|
||||
|
||||
_, err := ValidateInstanceLink("https://nat.museum-digital.de")
|
||||
|
||||
if err == nil {
|
||||
t.Fatalf("ValidateInstanceLink() accepts URLs of aggregated instance")
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Test that ValidateInstanceLink() works with a valid instance of md.
|
||||
func TestValidateInstanceWorks(t *testing.T) {
|
||||
|
||||
result, err := ValidateInstanceLink("https://hessen.museum-digital.de")
|
||||
|
||||
if err != nil {
|
||||
t.Fatalf("ValidateInstanceLink() returns an error where it should work")
|
||||
}
|
||||
if result != "https://hessen.museum-digital.de" {
|
||||
t.Fatalf("Output of ValidateInstanceLink() is not https://hessen.museum-digital.de where it should be")
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Test that ValidateInstanceLink() works with a valid instance of md and cleans paths.
|
||||
func TestValidateInstanceDoesCleanPathFromUrl(t *testing.T) {
|
||||
|
||||
result, err := ValidateInstanceLink("https://hessen.museum-digital.de/home")
|
||||
|
||||
if err != nil {
|
||||
t.Fatalf("ValidateInstanceLink() returns an error where it should work")
|
||||
}
|
||||
if result != "https://hessen.museum-digital.de" {
|
||||
t.Fatalf("Output of ValidateInstanceLink() is not https://hessen.museum-digital.de where it should be")
|
||||
}
|
||||
|
||||
|
||||
}
|
@@ -2,7 +2,6 @@ package configloader
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
@@ -16,17 +15,15 @@ func ValidateInstitutionId(institutionId int, instanceUrl string) (int, error) {
|
||||
return 0, errors.New("Institution ID cannot be negative")
|
||||
}
|
||||
|
||||
resp, err := http.Get(instanceUrl + "/institution/" + strconv.Itoa(institutionId))
|
||||
statusCode, err := HttpGetStatusCode(instanceUrl + "/institution/" + strconv.Itoa(institutionId))
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
if resp.StatusCode != 200 {
|
||||
if statusCode != 200 {
|
||||
return 0, errors.New("The institution page does not respond with HTTP 200, the institution does not seem to exist")
|
||||
}
|
||||
|
||||
|
||||
|
||||
return institutionId, nil
|
||||
|
||||
}
|
||||
|
15
src/configloader/ValidateMail.go
Normal file
15
src/configloader/ValidateMail.go
Normal file
@@ -0,0 +1,15 @@
|
||||
package configloader
|
||||
|
||||
import "net/mail"
|
||||
|
||||
// Validates an input mail address.
|
||||
// Returns the valid mail address or an eQueries therror.
|
||||
func ValidateMail(email string) (string, error) {
|
||||
|
||||
_, err := mail.ParseAddress(email)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
return email, nil
|
||||
|
||||
}
|
27
src/configloader/ValidateMail_test.go
Normal file
27
src/configloader/ValidateMail_test.go
Normal file
@@ -0,0 +1,27 @@
|
||||
package configloader
|
||||
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
// Test that ValidateMail() returns the mail address if it is valid.
|
||||
func TestValidateMailAcceptsValidMailAddress(t *testing.T) {
|
||||
|
||||
_, err := ValidateMail("test@example.com")
|
||||
|
||||
if err != nil {
|
||||
t.Fatalf("ValidateMail() returns an error on a valid mail address")
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Test that ValidateMail() filters out invalid mail addresses.
|
||||
func TestValidateMailDoesNotAcceptInvalidMailAddress(t *testing.T) {
|
||||
|
||||
_, err := ValidateMail("test")
|
||||
|
||||
if err == nil {
|
||||
t.Fatalf("ValidateMail() does not prevent entering an invalid mail address")
|
||||
}
|
||||
|
||||
}
|
@@ -1,67 +1,205 @@
|
||||
package configloader
|
||||
|
||||
import (
|
||||
"os"
|
||||
"encoding/json"
|
||||
"path/filepath"
|
||||
"io/ioutil"
|
||||
)
|
||||
|
||||
type MDWebDavUploaderConfig struct {
|
||||
InstanceLink string `json:"instance"`
|
||||
Mail string `json:"mail"`
|
||||
WebDavAuthToken string `json:"token"`
|
||||
InstitutionId int `json:"institution_id"`
|
||||
Parser string `json:"parser"`
|
||||
MetadataFolder string `json:"metadata_folder"`
|
||||
MediaFolder string `json:"media_folder"`
|
||||
PublishOnImport bool `json:"visible"`
|
||||
InstanceLink string `json:"instance"`
|
||||
Username string `json:"username"`
|
||||
Mail string `json:"mail"`
|
||||
WebDavAuthToken string `json:"token"`
|
||||
InstitutionId int `json:"institution_id"`
|
||||
Parser string `json:"parser"`
|
||||
UploadDir string `json:"upload_directory"`
|
||||
PublishOnImport bool `json:"visible"`
|
||||
Settings map[string]string `json:"settings"`
|
||||
}
|
||||
|
||||
type ParserListItem struct {
|
||||
name string
|
||||
|
||||
// Returns the file path of the configuration file within the supplied
|
||||
// directory. Moved to a dedicated function to provide a consistent
|
||||
// filename.
|
||||
func getConfigFileNameByDir(folder string) string {
|
||||
return filepath.Join(folder, "config.json")
|
||||
}
|
||||
|
||||
// Returns a uniform filepath for the configuration of this tool.
|
||||
// Returns a uniform directory for the configuration of this tool.
|
||||
// To be compatible across operating systems, this will be a JSON
|
||||
// file in the same directory as the current programm.
|
||||
func getConfigFilepath() string {
|
||||
func getConfigFilepath() (string, error) {
|
||||
|
||||
// Get the OS-dependent configuration directory.
|
||||
generalConfigDir, dirErr := os.UserConfigDir()
|
||||
if dirErr != nil {
|
||||
return "", dirErr
|
||||
}
|
||||
|
||||
// Select a subdirectory of that directory to store application-specific
|
||||
// settings in. Attempt to create it and return the config filepath as
|
||||
// a file in that directory.
|
||||
configDir := filepath.Join(generalConfigDir, "museum-digital-uploader")
|
||||
generateConfigDirErr := os.Mkdir(configDir, 0700)
|
||||
|
||||
// The config directory could be created, return path of the configuration
|
||||
// file in it.
|
||||
if generateConfigDirErr == nil {
|
||||
return getConfigFileNameByDir(configDir), nil // Use this to create files
|
||||
}
|
||||
|
||||
// There has been an error creating the config directory.
|
||||
// This may be either that the directory already exists, which is alright
|
||||
// (and even expected on most runs). Or it might be, that the path is
|
||||
// already occupied with a file. Or something else. In those cases,
|
||||
// the error should be returned.
|
||||
|
||||
// If the path is already occupied, inspect it more closely.
|
||||
if os.IsExist(generateConfigDirErr) {
|
||||
|
||||
info, err := os.Stat(configDir)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
// The directory already exists and is a directory. This is fine,
|
||||
// so we return the config filename in the existing config directory.
|
||||
if info.IsDir() {
|
||||
return getConfigFileNameByDir(configDir), nil // Use this to create files
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return "", generateConfigDirErr
|
||||
|
||||
}
|
||||
|
||||
// Returns a uniform filepath for the cache for the list of
|
||||
// available parsers.
|
||||
func getParserCacheFilepath() string {
|
||||
// Wrapper around getConfigFilepath() allowing for an override for testing.
|
||||
func getConfigFilepathOrOverride(overridePath string) (string, error) {
|
||||
|
||||
// Override path is not validated, as it should only be used
|
||||
// in test settings
|
||||
if overridePath != "" {
|
||||
return overridePath, nil
|
||||
}
|
||||
|
||||
configFilePath, err := getConfigFilepath()
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
return configFilePath, nil
|
||||
|
||||
}
|
||||
|
||||
// Validates each of the values of MDWebDavUploaderConfig.
|
||||
func ValidateConfig(conf MDWebDavUploaderConfig) (MDWebDavUploaderConfig, error) {
|
||||
|
||||
// Validate and clean instance link
|
||||
instanceLink, instanceErr := ValidateInstanceLink(conf.InstanceLink)
|
||||
if instanceErr != nil {
|
||||
return conf, instanceErr
|
||||
}
|
||||
conf.InstanceLink = instanceLink
|
||||
|
||||
// Validate and clean mail
|
||||
mailLink, mailErr := ValidateMail(conf.Mail)
|
||||
if mailErr != nil {
|
||||
return conf, mailErr
|
||||
}
|
||||
conf.Mail = mailLink
|
||||
|
||||
// Validate and clean institution ID
|
||||
institutionIdLink, institutionIdErr := ValidateInstitutionId(conf.InstitutionId, conf.InstanceLink)
|
||||
if institutionIdErr != nil {
|
||||
return conf, institutionIdErr
|
||||
}
|
||||
conf.InstitutionId = institutionIdLink
|
||||
|
||||
// Validate and clean parser
|
||||
parserLink, parserErr := ValidateParser(conf.Parser)
|
||||
if parserErr != nil {
|
||||
return conf, parserErr
|
||||
}
|
||||
conf.Parser = parserLink
|
||||
|
||||
// Validate and clean upload folder
|
||||
uploadDir, mFolderErr := ValidateUploadDir(conf.UploadDir)
|
||||
if mFolderErr != nil {
|
||||
return conf, mFolderErr
|
||||
}
|
||||
conf.UploadDir = uploadDir
|
||||
|
||||
return conf, nil
|
||||
|
||||
}
|
||||
|
||||
// Loads configuration from the configuration file (located using
|
||||
// getConfigFilepath()).
|
||||
func LoadFromFile() MDWebDavUploaderConfig {
|
||||
// The function parameter overridePath is only useful for test settings.
|
||||
// Outside those, set an empty string to use the default config path.
|
||||
// Output parameters:
|
||||
// 1: Config
|
||||
// 2: Requirement for a re-run of the setup
|
||||
// 3: Error
|
||||
func LoadFromFile(overridePath string) (MDWebDavUploaderConfig, bool, error) {
|
||||
|
||||
// Get config file path
|
||||
configFile, configFileErr := getConfigFilepathOrOverride(overridePath)
|
||||
if configFileErr != nil {
|
||||
return MDWebDavUploaderConfig{}, false, configFileErr
|
||||
}
|
||||
|
||||
// Read the file
|
||||
configFileBytes, ioErr := ioutil.ReadFile(configFile)
|
||||
if ioErr != nil {
|
||||
return MDWebDavUploaderConfig{}, true, ioErr
|
||||
}
|
||||
|
||||
// Parse the file into a configuration struct
|
||||
var data MDWebDavUploaderConfig
|
||||
unmarshalErr := json.Unmarshal(configFileBytes, &data)
|
||||
|
||||
if unmarshalErr != nil {
|
||||
return MDWebDavUploaderConfig{}, true, ioErr
|
||||
}
|
||||
|
||||
// Validate data - the configuration file may have been altered externally
|
||||
config, validationErr := ValidateConfig(data)
|
||||
if validationErr != nil {
|
||||
return MDWebDavUploaderConfig{}, true, validationErr
|
||||
}
|
||||
|
||||
// Config could be parsed
|
||||
return config, false, nil
|
||||
|
||||
}
|
||||
|
||||
// Stores a parser list to a cache file (located via
|
||||
// getParserCacheFilepath()).
|
||||
func StoreParserList(parserList []ParserListItem) {
|
||||
|
||||
}
|
||||
|
||||
// Returns a list of the available parsers.
|
||||
func ListParsers() []ParserListItem {
|
||||
|
||||
}
|
||||
|
||||
|
||||
// Checks if inputParser is in the list of available parsers.
|
||||
// Returns the parser name or an error.
|
||||
func ValidateParser(inputParser string) (string, error) {
|
||||
|
||||
}
|
||||
|
||||
// Validates an input mail address.
|
||||
// Returns the valid mail address or an eQueries therror.
|
||||
func ValidateMail(mail string) (string, error) {
|
||||
|
||||
}
|
||||
|
||||
// Validates an entered instance URL.
|
||||
// Returns the entered URL in a unified form (minus optional
|
||||
// trailing slashes and the /musdb suffix) or an error.
|
||||
func ValidateInstanceLink(instanceUrl string) (string, error) {
|
||||
// Stores a config from MDWebDavUploaderConfig to the config file.
|
||||
// As with LoadFromFile(), it is possible to provide an overridePath for testing.
|
||||
func StoreConfigToFile(conf MDWebDavUploaderConfig, overridePath string) error {
|
||||
|
||||
config, validationErr := ValidateConfig(conf)
|
||||
if validationErr != nil {
|
||||
return validationErr
|
||||
}
|
||||
|
||||
configFilePath, configFileErr := getConfigFilepathOrOverride(overridePath)
|
||||
if configFileErr != nil {
|
||||
return configFileErr
|
||||
}
|
||||
|
||||
configJson, encodeErr := json.Marshal(config)
|
||||
if encodeErr != nil {
|
||||
return encodeErr
|
||||
}
|
||||
|
||||
writeErr := ioutil.WriteFile(configFilePath, configJson, 0644)
|
||||
if writeErr != nil {
|
||||
return writeErr
|
||||
}
|
||||
|
||||
return nil
|
||||
|
||||
}
|
||||
|
173
src/configloader/configloader_test.go
Normal file
173
src/configloader/configloader_test.go
Normal file
@@ -0,0 +1,173 @@
|
||||
package configloader
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"os"
|
||||
"path/filepath"
|
||||
)
|
||||
|
||||
// Returns a generally valid config. Single values can then be
|
||||
// replaced with the actually tested contents.
|
||||
func getTestConfig() MDWebDavUploaderConfig {
|
||||
|
||||
input := MDWebDavUploaderConfig{}
|
||||
input.InstanceLink = "https://hessen.museum-digital.de/home"
|
||||
input.Mail = "test@example.com"
|
||||
input.InstitutionId = 1;
|
||||
input.Parser = "Lido"
|
||||
|
||||
tmpDir := os.TempDir()
|
||||
testDir := filepath.Join(tmpDir, "/existing-dir-for-import")
|
||||
mkdirErr := os.MkdirAll(testDir, os.ModePerm)
|
||||
if mkdirErr != nil {
|
||||
panic("Test failure: Failed to create test dir")
|
||||
}
|
||||
|
||||
input.UploadDir = testDir
|
||||
|
||||
return input
|
||||
|
||||
|
||||
}
|
||||
|
||||
// Test that ValidateConfig() fails on non-URLs.
|
||||
func TestValidateUploaderConfigFailsOnInvalidInstanceUrl(t *testing.T) {
|
||||
|
||||
input := getTestConfig()
|
||||
input.InstanceLink = "abcmuseum-digital.org"
|
||||
_, err := ValidateConfig(input)
|
||||
if err == nil {
|
||||
t.Fatalf("ValidateConfig() does not return an error on a non-URL (via ValidateInstanceLink)")
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Test that ValidateConfig cleans an instance URL as per ValidateInstanceLink().
|
||||
func TestValidateUploaderConfigCleansInstanceViaValidateInstanceLink(t *testing.T) {
|
||||
|
||||
input := getTestConfig()
|
||||
input.InstanceLink = "https://hessen.museum-digital.de/home"
|
||||
returnVal, _ := ValidateConfig(input)
|
||||
if returnVal.InstanceLink != "https://hessen.museum-digital.de" {
|
||||
t.Fatalf("Failed to clean up input URL")
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Test that ValidateConfig() fails on invalid mail.
|
||||
func TestValidateUploaderConfigFailsOnInvalidMail(t *testing.T) {
|
||||
|
||||
input := getTestConfig()
|
||||
input.Mail = "test"
|
||||
_, err := ValidateConfig(input)
|
||||
if err == nil {
|
||||
t.Fatalf("ValidateConfig() does not return an error on a mail address")
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Test that ValidateConfig() accepts a valid mail address.
|
||||
func TestValidateUploaderConfigAcceptsValidMail(t *testing.T) {
|
||||
|
||||
input := getTestConfig()
|
||||
input.Mail = "test@example.com"
|
||||
returnVal, _ := ValidateConfig(input)
|
||||
if returnVal.Mail != "test@example.com" {
|
||||
t.Fatalf("Failed to accept valid mail")
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Test that ValidateConfig() fails on negative / invalid IDs.
|
||||
func TestValidateUploaderConfigFailsOnInvalidInstitutionId(t *testing.T) {
|
||||
|
||||
input := getTestConfig()
|
||||
input.InstitutionId = -1
|
||||
_, err := ValidateConfig(input)
|
||||
if err == nil {
|
||||
t.Fatalf("ValidateConfig() does not return an error on an invalid institution ID")
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Test that ValidateConfig() accepts valid institution IDs.
|
||||
func TestValidateUploaderConfigAcceptsValidInstitutionId(t *testing.T) {
|
||||
|
||||
input := getTestConfig()
|
||||
input.InstitutionId = 1
|
||||
returnVal, _ := ValidateConfig(input)
|
||||
if returnVal.InstitutionId != 1 {
|
||||
t.Fatalf("Failed to accept valid institution ID")
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Test that ValidateConfig() fails on negative / invalid IDs.
|
||||
func TestValidateUploaderConfigFailsOnInvalidParser(t *testing.T) {
|
||||
|
||||
input := getTestConfig()
|
||||
input.Parser = "nonexistentparser"
|
||||
_, err := ValidateConfig(input)
|
||||
if err == nil {
|
||||
t.Fatalf("ValidateConfig() does not return an error on an invalid parser")
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Test that ValidateConfig() accepts valid ParserDs.
|
||||
func TestValidateUploaderConfigAcceptsValidParser(t *testing.T) {
|
||||
|
||||
input := getTestConfig()
|
||||
input.Parser = "ParserLido"
|
||||
returnVal, _ := ValidateConfig(input)
|
||||
if returnVal.Parser != "Lido" {
|
||||
t.Fatalf("Failed to accept and clean valid parser")
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Test that ValidateConfig() fails on non-existent folder.
|
||||
func TestValidateUploaderConfigFailsOnInvalidUploadDir(t *testing.T) {
|
||||
|
||||
input := getTestConfig()
|
||||
input.UploadDir = "nonexistentfolder"
|
||||
_, err := ValidateConfig(input)
|
||||
if err == nil {
|
||||
t.Fatalf("ValidateConfig() does not return an error on an invalid upload folder")
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Test that saving and reading config works.
|
||||
func TestWritingAndReadingConfigWorks(t *testing.T) {
|
||||
|
||||
input := getTestConfig()
|
||||
input, _ = ValidateConfig(input)
|
||||
|
||||
writeErr := StoreConfigToFile(input, input.UploadDir + "/config.json")
|
||||
if writeErr != nil {
|
||||
t.Log("Error:")
|
||||
t.Log(writeErr)
|
||||
t.Fatalf("Failed to write config to override path")
|
||||
}
|
||||
|
||||
loadedFromFile, setupRequired, err := LoadFromFile(input.UploadDir + "/config.json")
|
||||
|
||||
if setupRequired != false {
|
||||
t.Fatalf("Expected no setup to be required, but return value indicated thus")
|
||||
}
|
||||
if err != nil {
|
||||
t.Fatalf("Returned an error on trying to load config file")
|
||||
}
|
||||
// Golang can't compare structs with slices or maps
|
||||
if input.InstanceLink != loadedFromFile.InstanceLink || input.Mail != loadedFromFile.Mail || input.WebDavAuthToken != loadedFromFile.WebDavAuthToken || input.InstitutionId != loadedFromFile.InstitutionId || input.Parser != loadedFromFile.Parser || input.UploadDir != loadedFromFile.UploadDir || input.PublishOnImport != loadedFromFile.PublishOnImport {
|
||||
t.Log("Input")
|
||||
t.Log(input)
|
||||
|
||||
t.Log("Loaded output")
|
||||
t.Log(loadedFromFile)
|
||||
|
||||
t.Fatalf("Failed to write and then load the same config")
|
||||
}
|
||||
|
||||
}
|
1
src/configloader/parser_list.json
Normal file
1
src/configloader/parser_list.json
Normal file
File diff suppressed because one or more lines are too long
20
src/importconfiggen/GenerateImportConfig.go
Normal file
20
src/importconfiggen/GenerateImportConfig.go
Normal file
@@ -0,0 +1,20 @@
|
||||
package importconfiggen
|
||||
|
||||
import (
|
||||
"gitea.armuli.eu/museum-digital/museum-digital-webdav-uploader/src/configloader"
|
||||
)
|
||||
|
||||
func GenerateImportConfig(config configloader.MDWebDavUploaderConfig) string {
|
||||
|
||||
output := "# Generated by user: " + config.Username
|
||||
output += "\nmail: " + config.Mail + "\nparser: " + config.Parser
|
||||
|
||||
if config.Settings != nil {
|
||||
for settingKey, settingValue := range(config.Settings) {
|
||||
output += "\nsetting: " + settingKey + ": " + settingValue
|
||||
}
|
||||
}
|
||||
|
||||
return output
|
||||
|
||||
}
|
47
src/meta/CheckVersionIsUpToDate.go
Normal file
47
src/meta/CheckVersionIsUpToDate.go
Normal file
@@ -0,0 +1,47 @@
|
||||
package meta
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"encoding/xml"
|
||||
)
|
||||
|
||||
// Very reduced item, as only title, link and pubDate are useful for a version check.
|
||||
type Item struct {
|
||||
Title string `xml:"title"`
|
||||
Link string `xml:"link"`
|
||||
PubDate string `xml:"pubDate"`
|
||||
}
|
||||
|
||||
type Channel struct {
|
||||
Items []Item `xml:"item"`
|
||||
}
|
||||
|
||||
type Rss struct {
|
||||
Channel Channel `xml:"channel"`
|
||||
}
|
||||
|
||||
// Checks if the current version is up to date or not. If there is a newer / different
|
||||
// version.
|
||||
func CheckVersionIsUpToDate() (Item, error) {
|
||||
|
||||
resp, err := http.Get("https://gitea.armuli.eu/museum-digital/museum-digital-webdav-uploader/releases.rss")
|
||||
if err != nil {
|
||||
return Item{}, err
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
rss := Rss{}
|
||||
|
||||
decoder := xml.NewDecoder(resp.Body)
|
||||
decodeErr := decoder.Decode(&rss)
|
||||
if decodeErr != nil {
|
||||
return Item{}, err
|
||||
}
|
||||
|
||||
newestItem := rss.Channel.Items[0];
|
||||
if (newestItem.Title == GetVersion() || newestItem.Title == "v" + GetVersion()) {
|
||||
return Item{}, nil
|
||||
}
|
||||
return newestItem, nil
|
||||
|
||||
}
|
6
src/meta/meta.go
Normal file
6
src/meta/meta.go
Normal file
@@ -0,0 +1,6 @@
|
||||
package meta
|
||||
|
||||
// Returns current version number.
|
||||
func GetVersion() string {
|
||||
return "0.1.1"
|
||||
}
|
130
src/uploadsrcdir/ListLocalDirs.go
Normal file
130
src/uploadsrcdir/ListLocalDirs.go
Normal file
@@ -0,0 +1,130 @@
|
||||
package uploadsrcdir
|
||||
|
||||
import (
|
||||
"path/filepath"
|
||||
"fmt"
|
||||
"io/fs"
|
||||
"os"
|
||||
"runtime"
|
||||
"slices"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
"gitea.armuli.eu/museum-digital/museum-digital-webdav-uploader/src/configloader"
|
||||
)
|
||||
|
||||
var MetadataFileExts = []string{".xml", ".csv", ".json"}
|
||||
var MediaFileExts = []string{".jpg", ".jpeg", ".png", ".gif", ".bmp", ".tif", ".tiff", ".pdf", ".mp3", ".mp4"}
|
||||
|
||||
// Lists all files in a folder that are of any of the expected file extensions.
|
||||
func getFilesInDir(startPath string, fileExts []string) []os.FileInfo {
|
||||
|
||||
allFiles := []os.FileInfo{}
|
||||
filepath.WalkDir(startPath, func(path string, entry fs.DirEntry, err error) error {
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if slices.Contains(fileExts, filepath.Ext(entry.Name())) || slices.Contains(fileExts, strings.ToLower(filepath.Ext(entry.Name()))) {
|
||||
// add entry and it's size to dirMap
|
||||
file, err := entry.Info()
|
||||
if err != nil {
|
||||
fmt.Println("Error retrieving file info for:", err)
|
||||
} else {
|
||||
allFiles = append(allFiles, file)
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
|
||||
})
|
||||
|
||||
return allFiles
|
||||
|
||||
}
|
||||
|
||||
// Lists all files to upload in metadata directory
|
||||
func ListUploadableMetadata(config configloader.MDWebDavUploaderConfig) []os.FileInfo {
|
||||
|
||||
return getFilesInDir(config.UploadDir, MetadataFileExts);
|
||||
|
||||
}
|
||||
|
||||
// Lists all files to upload in metadata directory
|
||||
func ListUploadableMedia(config configloader.MDWebDavUploaderConfig) []os.FileInfo {
|
||||
|
||||
return getFilesInDir(config.UploadDir, MediaFileExts);
|
||||
|
||||
}
|
||||
|
||||
// Returns lists of uploadable folder contents grouped into a) metadata files and b) media files.
|
||||
func GetUploadableFiles(config configloader.MDWebDavUploaderConfig) ([]string, []string) {
|
||||
|
||||
metadataFiles := []string{}
|
||||
mediaFiles := []string{}
|
||||
|
||||
filepath.WalkDir(config.UploadDir, func(path string, entry fs.DirEntry, err error) error {
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if slices.Contains(MetadataFileExts, filepath.Ext(entry.Name())) || slices.Contains(MetadataFileExts, strings.ToLower(filepath.Ext(entry.Name()))) {
|
||||
metadataFiles = append(metadataFiles, path)
|
||||
}
|
||||
|
||||
if slices.Contains(MediaFileExts, filepath.Ext(entry.Name())) || slices.Contains(MediaFileExts, strings.ToLower(filepath.Ext(entry.Name()))) {
|
||||
mediaFiles = append(mediaFiles, path)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
||||
})
|
||||
|
||||
return metadataFiles, mediaFiles
|
||||
|
||||
}
|
||||
|
||||
// Checks if a list of files have been modified in the last minute.
|
||||
// If so, returns true.
|
||||
func CheckAnyFileIsTooRecent(files []string) bool {
|
||||
|
||||
now := time.Now()
|
||||
maxConcTasks := min(10, runtime.NumCPU())
|
||||
|
||||
// Set a semaphore to restrict the number of concurrent upload tasks.
|
||||
semaphore := make(chan struct{}, maxConcTasks)
|
||||
wg := &sync.WaitGroup{}
|
||||
|
||||
output := false
|
||||
|
||||
for _, f := range(files) {
|
||||
|
||||
semaphore <- struct{}{} // acquire
|
||||
wg.Add(1)
|
||||
|
||||
go func() {
|
||||
|
||||
defer wg.Done()
|
||||
file, fStatErr := os.Stat(f)
|
||||
if fStatErr != nil {
|
||||
panic("Failed to read file: " + f)
|
||||
}
|
||||
|
||||
if diff := now.Sub(file.ModTime()); diff < 1 * time.Minute {
|
||||
print("File " + file.Name() + " has been changed within the last minute\n")
|
||||
output = true
|
||||
}
|
||||
|
||||
<-semaphore // release
|
||||
|
||||
}()
|
||||
|
||||
}
|
||||
|
||||
wg.Wait()
|
||||
|
||||
return output
|
||||
|
||||
}
|
115
src/webdavupload/CheckRemoteContents.go
Normal file
115
src/webdavupload/CheckRemoteContents.go
Normal file
@@ -0,0 +1,115 @@
|
||||
package webdavupload
|
||||
|
||||
import (
|
||||
"os"
|
||||
"sync"
|
||||
"time"
|
||||
"github.com/studio-b12/gowebdav"
|
||||
"gitea.armuli.eu/museum-digital/museum-digital-webdav-uploader/src/configloader"
|
||||
)
|
||||
|
||||
// Takes a path on the webdav remote and reads folder contents from it.
|
||||
func listWebDavFolderContents(config configloader.MDWebDavUploaderConfig, path string) ([]os.FileInfo, error) {
|
||||
|
||||
c := gowebdav.NewClient(getWebDavHost(config), config.Username, config.WebDavAuthToken)
|
||||
c.Connect()
|
||||
|
||||
files, err := c.ReadDir(path)
|
||||
return files, err
|
||||
|
||||
}
|
||||
|
||||
// Returns a list of the files on the top level of the remote.
|
||||
func ListTopLevelContents(config configloader.MDWebDavUploaderConfig) ([]os.FileInfo, error) {
|
||||
return listWebDavFolderContents(config, ".")
|
||||
}
|
||||
|
||||
// Returns a list of the files in the current metadata dir of the remote.
|
||||
func ListMetadataDir(config configloader.MDWebDavUploaderConfig) ([]os.FileInfo, error) {
|
||||
return listWebDavFolderContents(config, "./IMPORT_XML")
|
||||
}
|
||||
|
||||
// Returns a list of the files in the current media dir of the remote.
|
||||
func ListMediaDir(config configloader.MDWebDavUploaderConfig) ([]os.FileInfo, error) {
|
||||
return listWebDavFolderContents(config, "./IMPORT_IMG")
|
||||
}
|
||||
|
||||
func checkImportConfigExists(c *gowebdav.Client) bool {
|
||||
|
||||
_, err := c.Stat("./import_config.txt")
|
||||
if gowebdav.IsErrNotFound(err) == true {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
|
||||
}
|
||||
|
||||
// Checks if a remote directory is free for updating:
|
||||
// This means it can be read, and it does not contain files more recent than
|
||||
// 10 minutes.
|
||||
func checkRemoteDirIsFree(c *gowebdav.Client, path string) bool {
|
||||
|
||||
now := time.Now()
|
||||
|
||||
// Check metadata dir
|
||||
files, err := c.ReadDir(path)
|
||||
|
||||
if err != nil {
|
||||
print("Failed to load remote contents")
|
||||
return false
|
||||
}
|
||||
|
||||
for _, f := range(files) {
|
||||
if diff := now.Sub(f.ModTime()); diff < 10 * time.Minute {
|
||||
print("File " + f.Name() + " has been recently renamed")
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
return true
|
||||
|
||||
}
|
||||
|
||||
// Checks if either the metadata or the image folder contains files that have
|
||||
// been changed in the last 10 minutes.
|
||||
// In this case, it can be assumed that there is a concurrent upload taking place.
|
||||
func checkRemoteImportFilesAreTooRecent(c *gowebdav.Client) bool {
|
||||
|
||||
var wg sync.WaitGroup
|
||||
var metadataDirFree bool
|
||||
var mediaDirFree bool
|
||||
|
||||
wg.Add(2)
|
||||
go func() {
|
||||
defer wg.Done()
|
||||
metadataDirFree = checkRemoteDirIsFree(c, "./IMPORT_XML")
|
||||
}()
|
||||
go func() {
|
||||
defer wg.Done()
|
||||
mediaDirFree = checkRemoteDirIsFree(c, "./IMPORT_IMG")
|
||||
}()
|
||||
wg.Wait()
|
||||
|
||||
if metadataDirFree == true && mediaDirFree == true {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
|
||||
}
|
||||
|
||||
// Checks the remote for the existence of an import_config.txt.
|
||||
func CheckRemoteIsFree(c *gowebdav.Client) bool {
|
||||
|
||||
if checkImportConfigExists(c) == true {
|
||||
return false
|
||||
}
|
||||
|
||||
// Check if the remote media and metadata directories currently
|
||||
// contain very recent files indicating a concurrent upload.
|
||||
if checkRemoteImportFilesAreTooRecent(c) == true {
|
||||
return false
|
||||
}
|
||||
|
||||
return true
|
||||
|
||||
}
|
35
src/webdavupload/Client.go
Normal file
35
src/webdavupload/Client.go
Normal file
@@ -0,0 +1,35 @@
|
||||
package webdavupload
|
||||
|
||||
import (
|
||||
"net/url"
|
||||
"strconv"
|
||||
"github.com/studio-b12/gowebdav"
|
||||
"gitea.armuli.eu/museum-digital/museum-digital-webdav-uploader/src/configloader"
|
||||
)
|
||||
|
||||
// Generates the path for a webdav endpoint for the configured instance and institution.
|
||||
func getWebDavHost(config configloader.MDWebDavUploaderConfig) string {
|
||||
|
||||
parsed, err := url.Parse(config.InstanceLink)
|
||||
if err != nil {
|
||||
panic("Your settings must be broken. Failed to load instance URL.")
|
||||
}
|
||||
|
||||
output := url.URL{
|
||||
Scheme: "https",
|
||||
Host: parsed.Host,
|
||||
Path: "/musdb/webdav/" + strconv.Itoa(config.InstitutionId),
|
||||
}
|
||||
|
||||
return output.String()
|
||||
|
||||
}
|
||||
|
||||
// Returns a WebDAV client for the current config.
|
||||
func GetWebdavClient(config configloader.MDWebDavUploaderConfig) *gowebdav.Client {
|
||||
|
||||
c := gowebdav.NewClient(getWebDavHost(config), config.Username, config.WebDavAuthToken)
|
||||
c.Connect()
|
||||
return c
|
||||
|
||||
}
|
132
src/webdavupload/Upload.go
Normal file
132
src/webdavupload/Upload.go
Normal file
@@ -0,0 +1,132 @@
|
||||
package webdavupload
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"path/filepath"
|
||||
"os"
|
||||
"io"
|
||||
"net/http"
|
||||
"runtime"
|
||||
"sync"
|
||||
"sync/atomic"
|
||||
"github.com/studio-b12/gowebdav"
|
||||
"gitea.armuli.eu/museum-digital/museum-digital-webdav-uploader/src/configloader"
|
||||
"gitea.armuli.eu/museum-digital/museum-digital-webdav-uploader/src/importconfiggen"
|
||||
)
|
||||
|
||||
// Writes an import config to the remote
|
||||
func SetImportConfigToTheRemote(c *gowebdav.Client, config configloader.MDWebDavUploaderConfig) error {
|
||||
|
||||
importConf := importconfiggen.GenerateImportConfig(config)
|
||||
return c.Write("import_config.txt", []byte(importConf), 0660)
|
||||
|
||||
}
|
||||
|
||||
// Uploads a list of files to the target folder.
|
||||
func uploadFiles(c *gowebdav.Client, w io.Writer, files []string, remoteTarget string, outputContext string) {
|
||||
|
||||
// Check if the io.Writer is a http writer
|
||||
_, wImplementsHttpFlusher := interface{}(w).(http.Flusher)
|
||||
|
||||
total := len(files)
|
||||
var counter atomic.Uint64
|
||||
|
||||
// Determine the number of upload tasks to be processed concurrently.
|
||||
// 10 will be a hard maximum to not spam the server.
|
||||
maxConcTasks := min(10, runtime.NumCPU())
|
||||
|
||||
// Set a semaphore to restrict the number of concurrent upload tasks.
|
||||
semaphore := make(chan struct{}, maxConcTasks)
|
||||
wg := &sync.WaitGroup{}
|
||||
|
||||
fmt.Fprintf(w, "Will upload %v files. Processing %v tasks at a time.\n", total, maxConcTasks)
|
||||
if wImplementsHttpFlusher == true {
|
||||
w.(http.Flusher).Flush()
|
||||
}
|
||||
|
||||
for _, f := range(files) {
|
||||
|
||||
semaphore <- struct{}{} // acquire
|
||||
wg.Add(1)
|
||||
|
||||
go func() {
|
||||
|
||||
defer wg.Done()
|
||||
|
||||
basename := filepath.Base(f)
|
||||
|
||||
file, fOpenErr := os.Open(f)
|
||||
if fOpenErr != nil {
|
||||
panic("Failed to read file: " + f)
|
||||
}
|
||||
defer file.Close()
|
||||
|
||||
c.WriteStream("./" + remoteTarget + "/" + basename, file, 0644)
|
||||
|
||||
counter.Add(1)
|
||||
fmt.Fprintf(w, "Uploading %d of %d - File: %s (%s)\n", counter, total, basename, outputContext)
|
||||
if wImplementsHttpFlusher == true {
|
||||
w.(http.Flusher).Flush()
|
||||
}
|
||||
|
||||
<-semaphore // release
|
||||
|
||||
}()
|
||||
|
||||
}
|
||||
|
||||
wg.Wait()
|
||||
fmt.Println("Done")
|
||||
|
||||
}
|
||||
|
||||
// Uploads the selected metadata files.
|
||||
func UploadMetadataFiles(c *gowebdav.Client, w io.Writer, files []string) {
|
||||
|
||||
uploadFiles(c, w, files, "IMPORT_XML", "Uploading metadata files")
|
||||
|
||||
}
|
||||
|
||||
// Uploads the selected media files.
|
||||
func UploadMediaFiles(c *gowebdav.Client, w io.Writer, files []string) {
|
||||
|
||||
uploadFiles(c, w, files, "IMPORT_IMG", "Uploading media files")
|
||||
|
||||
}
|
||||
|
||||
// Removes a list of files.
|
||||
func BatchUnlink(w io.Writer, files []string) {
|
||||
|
||||
_, wImplementsHttpFlusher := interface{}(w).(http.Flusher)
|
||||
|
||||
maxConcTasks := min(10, runtime.NumCPU())
|
||||
|
||||
// Set a semaphore to restrict the number of concurrent upload tasks.
|
||||
semaphore := make(chan struct{}, maxConcTasks)
|
||||
wg := &sync.WaitGroup{}
|
||||
|
||||
for _, f := range(files) {
|
||||
|
||||
semaphore <- struct{}{} // acquire
|
||||
wg.Add(1)
|
||||
|
||||
go func() {
|
||||
|
||||
defer wg.Done()
|
||||
err := os.Remove(f)
|
||||
if err != nil {
|
||||
panic("Failed to delete file " + f)
|
||||
}
|
||||
fmt.Fprintf(w, "Delete file %s\n", f)
|
||||
<-semaphore // release
|
||||
|
||||
}()
|
||||
|
||||
}
|
||||
|
||||
wg.Wait()
|
||||
if wImplementsHttpFlusher == true {
|
||||
w.(http.Flusher).Flush()
|
||||
}
|
||||
|
||||
}
|
25
src/webui/assets/index.htm
Normal file
25
src/webui/assets/index.htm
Normal file
@@ -0,0 +1,25 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>museum-digital uploader</title>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||
<meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
|
||||
<link rel="shortcut icon" sizes="16x16 32x32" href="/logo.svg" />
|
||||
<link rel="shortcut icon" sizes="64x64" href="/logo.svg" />
|
||||
<link rel="apple-touch-icon" sizes="256x256" href="/logo.svg" />
|
||||
<meta name="theme-color" content="#FFF" />
|
||||
|
||||
<link rel="stylesheet" type="text/css" href="/md-uploader.css" />
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<header>
|
||||
<img src="/logo.svg">
|
||||
<h1>museum-digital:uploader</h1>
|
||||
<span id="actions"></span>
|
||||
</header>
|
||||
<div id="wrap">
|
||||
<script type='text/javascript' src='/md-uploader.js' async></script>
|
||||
|
||||
</body>
|
||||
</html>
|
423
src/webui/assets/logo-md-code-black.svg
Normal file
423
src/webui/assets/logo-md-code-black.svg
Normal file
@@ -0,0 +1,423 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<!-- Created with Inkscape (http://www.inkscape.org/) -->
|
||||
|
||||
<svg
|
||||
width="1020"
|
||||
height="1020"
|
||||
id="svg2985"
|
||||
version="1.1"
|
||||
inkscape:version="1.2 (dc2aedaf03, 2022-05-15)"
|
||||
sodipodi:docname="logo-md-code-black.svg"
|
||||
inkscape:export-filename="mdlogo-code-512px.png"
|
||||
inkscape:export-xdpi="48.189999"
|
||||
inkscape:export-ydpi="48.189999"
|
||||
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
|
||||
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
xmlns:svg="http://www.w3.org/2000/svg"
|
||||
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
|
||||
xmlns:cc="http://creativecommons.org/ns#"
|
||||
xmlns:dc="http://purl.org/dc/elements/1.1/">
|
||||
<title
|
||||
id="title42">General logo for museum-digital (black background)</title>
|
||||
<defs
|
||||
id="defs2987" />
|
||||
<sodipodi:namedview
|
||||
id="base"
|
||||
pagecolor="#ffffff"
|
||||
bordercolor="#ffffff"
|
||||
borderopacity="0.0"
|
||||
inkscape:pageopacity="0.0"
|
||||
inkscape:pageshadow="0"
|
||||
inkscape:zoom="0.98994949"
|
||||
inkscape:cx="375.27167"
|
||||
inkscape:cy="658.11439"
|
||||
inkscape:document-units="px"
|
||||
inkscape:current-layer="layer1"
|
||||
showgrid="false"
|
||||
inkscape:window-width="3840"
|
||||
inkscape:window-height="2076"
|
||||
inkscape:window-x="0"
|
||||
inkscape:window-y="-33"
|
||||
inkscape:window-maximized="1"
|
||||
fit-margin-top="5"
|
||||
fit-margin-left="5"
|
||||
fit-margin-right="5"
|
||||
fit-margin-bottom="5"
|
||||
showguides="false"
|
||||
inkscape:showpageshadow="2"
|
||||
inkscape:pagecheckerboard="0"
|
||||
inkscape:deskcolor="#d1d1d1" />
|
||||
<metadata
|
||||
id="metadata2990">
|
||||
<rdf:RDF>
|
||||
<cc:Work
|
||||
rdf:about="">
|
||||
<dc:format>image/svg+xml</dc:format>
|
||||
<dc:type
|
||||
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
|
||||
<cc:license
|
||||
rdf:resource="http://creativecommons.org/licenses/by/4.0/" />
|
||||
<dc:title>General logo for museum-digital (black background)</dc:title>
|
||||
<dc:date>2019</dc:date>
|
||||
<dc:creator>
|
||||
<cc:Agent>
|
||||
<dc:title>museum-digital</dc:title>
|
||||
</cc:Agent>
|
||||
</dc:creator>
|
||||
</cc:Work>
|
||||
<cc:License
|
||||
rdf:about="http://creativecommons.org/licenses/by/4.0/">
|
||||
<cc:permits
|
||||
rdf:resource="http://creativecommons.org/ns#Reproduction" />
|
||||
<cc:permits
|
||||
rdf:resource="http://creativecommons.org/ns#Distribution" />
|
||||
<cc:requires
|
||||
rdf:resource="http://creativecommons.org/ns#Notice" />
|
||||
<cc:requires
|
||||
rdf:resource="http://creativecommons.org/ns#Attribution" />
|
||||
<cc:permits
|
||||
rdf:resource="http://creativecommons.org/ns#DerivativeWorks" />
|
||||
</cc:License>
|
||||
</rdf:RDF>
|
||||
</metadata>
|
||||
<g
|
||||
inkscape:label="Layer 1"
|
||||
inkscape:groupmode="layer"
|
||||
id="layer1"
|
||||
transform="translate(8,-40.362183)">
|
||||
<rect
|
||||
style="fill:#000000;fill-opacity:1;stroke:#000000;stroke-width:8.82220364;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
|
||||
id="rect845"
|
||||
width="1011.1779"
|
||||
height="1011.1778"
|
||||
x="-3.5888982"
|
||||
y="44.773335"
|
||||
ry="0" />
|
||||
<flowRoot
|
||||
xml:space="preserve"
|
||||
id="flowRoot3763"
|
||||
style="font-style:normal;font-weight:normal;line-height:0.01%;font-family:sans-serif;text-align:end;letter-spacing:0px;word-spacing:0px;text-anchor:end;fill:#ffffff;fill-opacity:1;stroke:#ffffff;stroke-opacity:1"
|
||||
transform="matrix(1.0379746,0,0,1.0379746,-169.56958,-12.773255)"
|
||||
inkscape:export-xdpi="96.379997"
|
||||
inkscape:export-ydpi="96.379997"><flowRegion
|
||||
id="flowRegion3765"
|
||||
style="font-family:sans-serif;fill:#ffffff;fill-opacity:1;stroke:#ffffff;stroke-opacity:1"><rect
|
||||
id="rect3767"
|
||||
width="1008.1323"
|
||||
height="1000.051"
|
||||
x="-6.0609155"
|
||||
y="50.290859"
|
||||
style="font-family:sans-serif;text-align:end;text-anchor:end;fill:#ffffff;fill-opacity:1;stroke:#ffffff;stroke-opacity:1" /></flowRegion><flowPara
|
||||
id="flowPara3769"
|
||||
style="font-size:40px;line-height:1.25;font-family:sans-serif;fill:#ffffff;fill-opacity:1;stroke:#ffffff;stroke-opacity:1"> </flowPara></flowRoot>
|
||||
<text
|
||||
xml:space="preserve"
|
||||
style="font-style:normal;font-variant:normal;font-stretch:normal;font-size:12.4557px;line-height:0%;font-family:'Bookman Old Style';-inkscape-font-specification:'Bookman Old Style Semi-Light';text-align:center;letter-spacing:0px;word-spacing:0px;text-anchor:middle;fill:#ffffff;fill-opacity:1;stroke:#ffffff;stroke-width:1.03797;stroke-opacity:1"
|
||||
x="348.29947"
|
||||
y="659.89093"
|
||||
id="text3771"
|
||||
inkscape:export-xdpi="96.379997"
|
||||
inkscape:export-ydpi="96.379997" />
|
||||
<rect
|
||||
style="fill:#ffffff;fill-opacity:1;stroke:#ffffff;stroke-width:12.98119068;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
|
||||
id="rect833"
|
||||
width="79.41317"
|
||||
height="79.41317"
|
||||
x="98.490639"
|
||||
y="742.45844"
|
||||
rx="0"
|
||||
ry="0"
|
||||
inkscape:export-xdpi="96.379997"
|
||||
inkscape:export-ydpi="96.379997" />
|
||||
<rect
|
||||
style="fill:#ffffff;fill-opacity:1;stroke:#ffffff;stroke-width:12.98119068;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
|
||||
id="rect833-3"
|
||||
width="79.413177"
|
||||
height="79.41317"
|
||||
x="98.490639"
|
||||
y="626.96552"
|
||||
rx="0"
|
||||
ry="0"
|
||||
inkscape:export-xdpi="96.379997"
|
||||
inkscape:export-ydpi="96.379997" />
|
||||
<rect
|
||||
style="fill:#ffffff;fill-opacity:1;stroke:#ffffff;stroke-width:12.98119068;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
|
||||
id="rect833-6"
|
||||
width="79.41317"
|
||||
height="79.41317"
|
||||
x="98.490639"
|
||||
y="511.47241"
|
||||
rx="0"
|
||||
ry="0"
|
||||
inkscape:export-xdpi="96.379997"
|
||||
inkscape:export-ydpi="96.379997" />
|
||||
<rect
|
||||
style="fill:none;fill-opacity:1;stroke:#ffffff;stroke-width:10.21611977;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
|
||||
id="rect833-3-7"
|
||||
width="82.178253"
|
||||
height="47.530357"
|
||||
x="97.108063"
|
||||
y="429.24481"
|
||||
rx="0"
|
||||
ry="0"
|
||||
inkscape:export-xdpi="96.379997"
|
||||
inkscape:export-ydpi="96.379997" />
|
||||
<rect
|
||||
style="fill:#ffffff;fill-opacity:1;stroke:#ffffff;stroke-width:12.98119068;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
|
||||
id="rect833-5"
|
||||
width="79.413162"
|
||||
height="79.41317"
|
||||
x="271.73004"
|
||||
y="742.45844"
|
||||
rx="0"
|
||||
ry="0"
|
||||
inkscape:export-xdpi="96.379997"
|
||||
inkscape:export-ydpi="96.379997" />
|
||||
<rect
|
||||
style="fill:#ffffff;fill-opacity:1;stroke:#ffffff;stroke-width:12.98119068;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
|
||||
id="rect833-3-3"
|
||||
width="79.41317"
|
||||
height="79.41317"
|
||||
x="271.73004"
|
||||
y="626.96552"
|
||||
rx="0"
|
||||
ry="0"
|
||||
inkscape:export-xdpi="96.379997"
|
||||
inkscape:export-ydpi="96.379997" />
|
||||
<rect
|
||||
style="fill:#ffffff;fill-opacity:1;stroke:#ffffff;stroke-width:12.98119068;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
|
||||
id="rect833-6-5"
|
||||
width="79.413162"
|
||||
height="79.41317"
|
||||
x="271.73004"
|
||||
y="511.47241"
|
||||
rx="0"
|
||||
ry="0"
|
||||
inkscape:export-xdpi="96.379997"
|
||||
inkscape:export-ydpi="96.379997" />
|
||||
<rect
|
||||
style="fill:#ffffff;fill-opacity:1;stroke:#ffffff;stroke-width:12.98119068;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
|
||||
id="rect833-5-6"
|
||||
width="79.413162"
|
||||
height="79.41317"
|
||||
x="444.96948"
|
||||
y="742.45844"
|
||||
rx="0"
|
||||
ry="0"
|
||||
inkscape:export-xdpi="96.379997"
|
||||
inkscape:export-ydpi="96.379997" />
|
||||
<rect
|
||||
style="fill:#ffffff;fill-opacity:1;stroke:#ffffff;stroke-width:12.98119068;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
|
||||
id="rect833-3-3-2"
|
||||
width="79.41317"
|
||||
height="79.41317"
|
||||
x="444.96948"
|
||||
y="626.96545"
|
||||
rx="0"
|
||||
ry="0"
|
||||
inkscape:export-xdpi="96.379997"
|
||||
inkscape:export-ydpi="96.379997" />
|
||||
<rect
|
||||
style="fill:#ffffff;fill-opacity:1;stroke:#ffffff;stroke-width:12.98119068;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
|
||||
id="rect833-6-5-9"
|
||||
width="79.413162"
|
||||
height="79.41317"
|
||||
x="444.96948"
|
||||
y="511.47235"
|
||||
rx="0"
|
||||
ry="39.706581"
|
||||
inkscape:export-xdpi="96.379997"
|
||||
inkscape:export-ydpi="96.379997" />
|
||||
<rect
|
||||
style="fill:#ffffff;fill-opacity:1;stroke:#ffffff;stroke-width:10.21612072;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
|
||||
id="rect833-6-5-1"
|
||||
width="47.530357"
|
||||
height="82.178246"
|
||||
x="201.05171"
|
||||
y="510.08987"
|
||||
rx="0"
|
||||
ry="0"
|
||||
inkscape:export-xdpi="96.379997"
|
||||
inkscape:export-ydpi="96.379997" />
|
||||
<rect
|
||||
style="fill:#ffffff;fill-opacity:1;stroke:#ffffff;stroke-width:10.21612072;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
|
||||
id="rect833-6-5-1-2"
|
||||
width="47.530357"
|
||||
height="82.178246"
|
||||
x="374.29114"
|
||||
y="510.08987"
|
||||
rx="0"
|
||||
ry="0"
|
||||
inkscape:export-xdpi="96.379997"
|
||||
inkscape:export-ydpi="96.379997" />
|
||||
<rect
|
||||
style="fill:#ffffff;fill-opacity:1;stroke:#ffffff;stroke-width:12.98119068;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
|
||||
id="rect833-6-5-9-7"
|
||||
width="79.413162"
|
||||
height="79.41317"
|
||||
x="595.11035"
|
||||
y="742.45844"
|
||||
rx="0"
|
||||
ry="0"
|
||||
inkscape:export-xdpi="96.379997"
|
||||
inkscape:export-ydpi="96.379997" />
|
||||
<rect
|
||||
style="fill:#ffffff;fill-opacity:1;stroke:#ffffff;stroke-width:12.98119068;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
|
||||
id="rect833-6-5-9-7-0"
|
||||
width="79.413162"
|
||||
height="79.41317"
|
||||
x="710.60327"
|
||||
y="742.45844"
|
||||
rx="0"
|
||||
ry="0"
|
||||
inkscape:transform-center-x="-9.9165682"
|
||||
inkscape:transform-center-y="47.832846"
|
||||
inkscape:export-xdpi="96.379997"
|
||||
inkscape:export-ydpi="96.379997" />
|
||||
<rect
|
||||
style="fill:#ffffff;fill-opacity:1;stroke:#ffffff;stroke-width:12.98119068;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
|
||||
id="rect833-6-5-9-7-9"
|
||||
width="79.413162"
|
||||
height="79.41317"
|
||||
x="826.09625"
|
||||
y="742.45844"
|
||||
rx="0"
|
||||
ry="0"
|
||||
inkscape:export-xdpi="96.379997"
|
||||
inkscape:export-ydpi="96.379997" />
|
||||
<rect
|
||||
style="fill:#ffffff;fill-opacity:1;stroke:#ffffff;stroke-width:12.98119068;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
|
||||
id="rect833-6-5-9-7-3"
|
||||
width="79.413162"
|
||||
height="79.41317"
|
||||
x="595.11035"
|
||||
y="626.96552"
|
||||
rx="0"
|
||||
ry="0"
|
||||
inkscape:export-xdpi="96.379997"
|
||||
inkscape:export-ydpi="96.379997" />
|
||||
<rect
|
||||
style="fill:#ffffff;fill-opacity:1;stroke:#ffffff;stroke-width:12.98119068;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
|
||||
id="rect833-6-5-9-7-3-6"
|
||||
width="79.413162"
|
||||
height="79.41317"
|
||||
x="595.11035"
|
||||
y="511.47241"
|
||||
rx="0"
|
||||
ry="39.706581"
|
||||
inkscape:transform-center-x="-29.166407"
|
||||
inkscape:transform-center-y="139.41528"
|
||||
inkscape:export-xdpi="96.379997"
|
||||
inkscape:export-ydpi="96.379997" />
|
||||
<rect
|
||||
style="fill:#ffffff;fill-opacity:1;stroke:#ffffff;stroke-width:12.98119068;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
|
||||
id="rect833-6-5-9-7-3-6-0"
|
||||
width="79.413162"
|
||||
height="79.41317"
|
||||
x="710.60327"
|
||||
y="511.47241"
|
||||
rx="0"
|
||||
ry="0"
|
||||
inkscape:transform-center-x="-29.166375"
|
||||
inkscape:transform-center-y="139.41528"
|
||||
inkscape:export-xdpi="96.379997"
|
||||
inkscape:export-ydpi="96.379997" />
|
||||
<rect
|
||||
style="fill:none;fill-opacity:1;stroke:#ffffff;stroke-width:12.98119068;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
|
||||
id="rect833-6-5-9-7-6"
|
||||
width="79.413162"
|
||||
height="79.41317"
|
||||
x="826.09625"
|
||||
y="626.96552"
|
||||
rx="0"
|
||||
ry="0"
|
||||
inkscape:export-xdpi="96.379997"
|
||||
inkscape:export-ydpi="96.379997" />
|
||||
<rect
|
||||
style="fill:#ffffff;fill-opacity:1;stroke:#ffffff;stroke-width:12.98119068;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
|
||||
id="rect833-6-5-9-7-3-2"
|
||||
width="79.413162"
|
||||
height="79.41317"
|
||||
x="826.09625"
|
||||
y="511.47241"
|
||||
rx="0"
|
||||
ry="0"
|
||||
inkscape:export-xdpi="96.379997"
|
||||
inkscape:export-ydpi="96.379997" />
|
||||
<rect
|
||||
style="fill:#ffffff;fill-opacity:1;stroke:#ffffff;stroke-width:12.98119068;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
|
||||
id="rect833-6-5-9-7-3-6-6"
|
||||
width="79.413162"
|
||||
height="79.41317"
|
||||
x="826.09625"
|
||||
y="395.97949"
|
||||
rx="0"
|
||||
ry="0"
|
||||
inkscape:transform-center-x="-29.166404"
|
||||
inkscape:transform-center-y="139.4153"
|
||||
inkscape:export-xdpi="96.379997"
|
||||
inkscape:export-ydpi="96.379997" />
|
||||
<rect
|
||||
style="fill:#ffffff;fill-opacity:1;stroke:#ffffff;stroke-width:12.98119068;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
|
||||
id="rect833-6-5-9-7-3-6-6-1"
|
||||
width="79.413162"
|
||||
height="79.41317"
|
||||
x="826.09625"
|
||||
y="280.48651"
|
||||
rx="0"
|
||||
ry="0"
|
||||
inkscape:transform-center-x="-29.166404"
|
||||
inkscape:transform-center-y="139.41528"
|
||||
inkscape:export-xdpi="96.379997"
|
||||
inkscape:export-ydpi="96.379997" />
|
||||
<rect
|
||||
style="fill:#ffffff;fill-opacity:1;stroke:#ffffff;stroke-width:9.61340618;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
|
||||
id="rect833-6-5-9-3"
|
||||
width="41.781116"
|
||||
height="82.780952"
|
||||
x="443.28558"
|
||||
y="509.78845"
|
||||
rx="0"
|
||||
ry="0"
|
||||
inkscape:export-xdpi="96.379997"
|
||||
inkscape:export-ydpi="96.379997" />
|
||||
<rect
|
||||
style="fill:#ffffff;fill-opacity:1;stroke:#ffffff;stroke-width:9.61340523;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
|
||||
id="rect833-6-5-9-75"
|
||||
width="82.780945"
|
||||
height="41.78112"
|
||||
x="443.28558"
|
||||
y="550.78833"
|
||||
rx="0"
|
||||
ry="0"
|
||||
inkscape:export-xdpi="96.379997"
|
||||
inkscape:export-ydpi="96.379997" />
|
||||
<rect
|
||||
style="fill:#ffffff;fill-opacity:1;stroke:#ffffff;stroke-width:9.61340523;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
|
||||
id="rect833-6-5-9-7-3-6-3"
|
||||
width="82.780945"
|
||||
height="41.78112"
|
||||
x="593.42645"
|
||||
y="550.78839"
|
||||
rx="0"
|
||||
ry="0"
|
||||
inkscape:transform-center-x="-30.4033"
|
||||
inkscape:transform-center-y="73.349637"
|
||||
inkscape:export-xdpi="96.379997"
|
||||
inkscape:export-ydpi="96.379997" />
|
||||
<rect
|
||||
style="fill:#ffffff;fill-opacity:1;stroke:#ffffff;stroke-width:9.61340523;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
|
||||
id="rect833-6-5-9-7-3-6-5"
|
||||
width="41.781116"
|
||||
height="82.780952"
|
||||
x="634.42627"
|
||||
y="509.78851"
|
||||
rx="0"
|
||||
ry="0"
|
||||
inkscape:transform-center-x="-15.345135"
|
||||
inkscape:transform-center-y="145.32765"
|
||||
inkscape:export-xdpi="96.379997"
|
||||
inkscape:export-ydpi="96.379997" />
|
||||
</g>
|
||||
</svg>
|
After Width: | Height: | Size: 15 KiB |
183
src/webui/assets/md-uploader.css
Normal file
183
src/webui/assets/md-uploader.css
Normal file
@@ -0,0 +1,183 @@
|
||||
:root {
|
||||
--color-bg: #FFF;
|
||||
--color-bg2: #F5F5F5;
|
||||
--color-fg: #000;
|
||||
--color-fg2: #212121;
|
||||
--color-bg-dark: #212121;
|
||||
--color-fg-medium: #484848;
|
||||
--color-borders: #D6D6D6;
|
||||
|
||||
--color-accent: #546E7A;
|
||||
--color-accent-hover: #455A64;
|
||||
--color-accent-focus: #78909C;
|
||||
|
||||
--def-padding-main: 1em;
|
||||
--def-border-radius: 6px;
|
||||
}
|
||||
|
||||
|
||||
@media (prefers-color-scheme: dark) {
|
||||
|
||||
:root {
|
||||
--color-bg: #000;
|
||||
--color-bg2: #2685AF;
|
||||
--color-fg: #FFF;
|
||||
--color-fg2: #D6D6D6;
|
||||
--color-bg-dark: #212121;
|
||||
--color-fg-medium: #BDBDBD;
|
||||
--color-borders: #424242;
|
||||
|
||||
--color-accent: #546E7A;
|
||||
--color-accent-hover: #90A4AE;
|
||||
--color-accent-focus: #78909C;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
html {
|
||||
background:
|
||||
linear-gradient(135deg,#0000 18.75%,var(--color-bg2) 0 31.25%,#0000 0),
|
||||
repeating-linear-gradient(45deg,var(--color-bg2) -6.25% 6.25%,var(--color-bg) 0 18.75%);
|
||||
background-size: 64px 64px;
|
||||
color: var(--color-fg);
|
||||
padding: 0;
|
||||
font-family: Sans;
|
||||
}
|
||||
|
||||
body { margin: 0; padding: 0; }
|
||||
|
||||
header { display: grid; grid-template-columns: auto auto 100fr auto;
|
||||
align-items: center;
|
||||
background: var(--color-bg); font-size: 1.5em; padding: .4em 2rem;
|
||||
box-shadow: 0 4px 2px -2px var(--color-borders); }
|
||||
header * { margin: 0; padding: 0; vertical-align: middle; }
|
||||
header img { height: 1em; }
|
||||
|
||||
header #actions { grid-column: 4; font-size: .85rem; font-weight: bold; }
|
||||
header #actions > * { padding: .2em .5em;
|
||||
border-radius: .2em; color: var(--color-fg2); transition: .2s; }
|
||||
header #actions > :hover { background: var(--color-accent-hover); color: var(--color-bg); }
|
||||
|
||||
h1 { display: inline-block; margin-left: 1em; font-size: .8em; }
|
||||
|
||||
#wrap { display: grid;
|
||||
grid-template-columns: 450px 1fr; grid-template-rows: auto auto;
|
||||
margin: 1em 2rem; grid-gap: 2em; }
|
||||
#wrap > * { vertical-align: top; }
|
||||
|
||||
main,
|
||||
aside,
|
||||
.sec-aside { background: var(--color-bg); border-radius: 1px solid var(--color-borders); box-shadow: 0 0 6px var(--color-borders); border-radius: 2px; }
|
||||
|
||||
aside,
|
||||
.sec-aside { grid-column: 1; }
|
||||
main { grid-column: 2; grid-row: 1 / span 2; }
|
||||
|
||||
h2 { margin: 0; padding: .8rem; font-size: 1.4em;
|
||||
border-bottom: .15em solid var(--color-borders); }
|
||||
h3 { margin: 0; padding: .8rem; border-bottom: .15em solid var(--color-borders); }
|
||||
|
||||
input { background: var(--color-bg); color: var(--color-fg); }
|
||||
|
||||
aside .label-input { display: grid;
|
||||
grid-template-columns: 150px auto 2em; border-bottom: 1px solid var(--color-borders); }
|
||||
aside .label-input:hover { border-color: var(--color-accent); }
|
||||
aside .label-input > * { display: inline-block;
|
||||
font-size: .9em;
|
||||
padding: .5rem .8rem; border: 0; outline: 0; }
|
||||
aside label { font-weight: bold; color: var(--color-fg-medium); }
|
||||
|
||||
aside .label-input button { background: none; transition: background .2s; }
|
||||
aside .label-input button:hover { background: var(--color-accent); }
|
||||
|
||||
.icon-help:before { content: " ? "; font-weight: bold; font-size: .8em;
|
||||
text-align: center; color: var(--color-fg2); transition: background .2s; }
|
||||
.icon-help { transition: background .2s; }
|
||||
.icon-help:hover { background: var(--color-accent); }
|
||||
|
||||
select { width: 100%; background: var(--color-bg); color: var(--color-fg); }
|
||||
|
||||
.updateB { display: block; width: calc(100% - 1em); background: var(--color-bg);
|
||||
margin: .5em; padding: .5em;
|
||||
text-align: center;
|
||||
border: 1px solid var(--color-bg); border-radius: 2px; font-weight: bold;
|
||||
color: var(--color-accent); transition: background .2s, color .2s;}
|
||||
.updateB:hover { background: var(--color-accent-hover); color: var(--color-bg); }
|
||||
|
||||
.upload-file-list > span { display: block;
|
||||
padding: .3em .8rem;
|
||||
font-family: Mono, Courier; font-size: .9em;
|
||||
border-bottom: 1px solid var(--color-borders); transition: border .2s, background .2s; }
|
||||
.upload-file-list > span:hover { background: var(--color-bg2); border-color: var(--color-accent-hover); }
|
||||
|
||||
.upload-file-list:empty { display: block; position: relative; height: 5em; }
|
||||
.upload-file-list:empty:before { content: " - - - - - ";
|
||||
position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%);
|
||||
font-weight: bold; font-size: 3em; color: var(--color-borders); }
|
||||
|
||||
main { position: relative; }
|
||||
main h3 { position: sticky; top: 0; background: var(--color-bg); }
|
||||
|
||||
.transfer-overlay { display: block;
|
||||
position: fixed; left: 5em; bottom: 0; width: calc(100% - 10em);
|
||||
background: var(--color-bg);
|
||||
border: 2px solid var(--color-accent-hover); border-bottom-width: 0;
|
||||
box-shadow: 0 0 6px var(--color-borders);
|
||||
z-index: 10; animation: slide-up .4s ease-out; }
|
||||
.transfer-overlay h3 { border-bottom: none; }
|
||||
.transfer-overlay-hl { display: grid; grid-template-columns: auto 1fr auto;
|
||||
padding-right: .8em;
|
||||
align-items: center; border-bottom: .15em solid var(--color-borders); }
|
||||
.transfer-overlay-hl .overlay-close { display: inline-block;
|
||||
color: var(--color-fg2);
|
||||
padding: .5em; border-radius: 2px;
|
||||
grid-column: 3;
|
||||
transition: .2s; }
|
||||
.transfer-overlay-hl .overlay-close:hover { background: var(--color-accent-hover); color: var(--color-bg); }
|
||||
.transfer-overlay-hl .overlay-close:before { display: inline-block; content: " x ";}
|
||||
|
||||
.transfer-msgs { font-size: .9em; }
|
||||
.transfer-msgs > * { display: block; border-bottom: 1px solid var(--color-borders); transition: .2s; }
|
||||
|
||||
.transfer-msgs > :hover { border-bottom-color: 1px solid var(--color-accent-hover); }
|
||||
|
||||
@keyframes slide-up {
|
||||
from { transform: translateY(100%); }
|
||||
to { transform: initial; }
|
||||
}
|
||||
|
||||
iframe { display: block; width: 100%; border: none; height: 60vh; }
|
||||
.parser-desc { display: block; padding: 0 .8rem;
|
||||
font-size: .85em; white-space: pre-wrap; }
|
||||
|
||||
#wrap.setup-required { grid-template-columns: 1fr 450px 1fr; justify-content: center; }
|
||||
.setup-required aside { grid-column: 2; width: 450px; margin: auto; }
|
||||
.setup-required main { display: none; }
|
||||
|
||||
/***
|
||||
* Slider
|
||||
* Thanks: mrhyddenn
|
||||
* The following CSS slider is licensed under the MIT license, 2025 mrhyddenn.
|
||||
* https://uiverse.io/mrhyddenn/old-fish-66
|
||||
* */
|
||||
/* The switch - the box around the slider */
|
||||
.switch { font-size: 17px; position: relative; display: inline-block; width: 62px; height: 35px; transform: scale(0.8); }
|
||||
|
||||
/* Hide default HTML checkbox */
|
||||
.switch input { opacity: 1; width: 0; height: 0;
|
||||
}
|
||||
|
||||
/* The slider */
|
||||
.slider { position: absolute; cursor: pointer; top: 0; left: 0; right: 0; bottom: 0px;
|
||||
background: var(--color-bg); transition: .4s; border-radius: 30px; border: 1px solid var(--color-borders);
|
||||
}
|
||||
|
||||
.slider:before { position: absolute; content: "";
|
||||
height: 1.9em; width: 1.9em; border-radius: 16px; left: 1.2px; top: 0; bottom: 0
|
||||
background-color: var(--color-bg); box-shadow: 0 2px 5px var(--color-accent-hover); transition: .4s;
|
||||
}
|
||||
|
||||
input:checked + .slider { background-color: var(--color-accent); border: 1px solid transparent;
|
||||
}
|
||||
|
||||
input:checked + .slider:before { transform: translateX(1.5em); background-color: var(--color-accent-focus); }
|
492
src/webui/assets/md-uploader.js
Normal file
492
src/webui/assets/md-uploader.js
Normal file
@@ -0,0 +1,492 @@
|
||||
"use strict";
|
||||
|
||||
class App {
|
||||
|
||||
lang;
|
||||
tls;
|
||||
config;
|
||||
parserList;
|
||||
uploadableFiles;
|
||||
wrap;
|
||||
actionsArea;
|
||||
aside;
|
||||
main;
|
||||
|
||||
generateTextElement(type, value) {
|
||||
const elem = document.createElement(type);
|
||||
elem.textContent = value;
|
||||
return elem;
|
||||
}
|
||||
|
||||
generateLabelInput(id, labelText, explanationText, type, value) {
|
||||
|
||||
const output = document.createElement("div");
|
||||
output.classList.add("label-input");
|
||||
|
||||
const label = document.createElement("label");
|
||||
label.textContent = labelText;
|
||||
label.setAttribute("for", id);
|
||||
output.appendChild(label);
|
||||
|
||||
const input = document.createElement("input");
|
||||
input.id = id;
|
||||
input.type = "text";
|
||||
input.value = value;
|
||||
output.appendChild(input);
|
||||
|
||||
const help = document.createElement("span");
|
||||
help.classList.add("icon-help");
|
||||
help.title = explanationText;
|
||||
output.appendChild(help);
|
||||
|
||||
return {'wrap': output, 'input': input};
|
||||
|
||||
}
|
||||
|
||||
async generateSidebar() {
|
||||
|
||||
this.aside.appendChild(this.generateTextElement("h2", this.tls.settings));
|
||||
|
||||
// Set up fields
|
||||
const instanceLinkArea = this.generateLabelInput("instance-link",
|
||||
this.tls.instance_link, this.tls.instance_link_explica, "url", this.config.settings.instance);
|
||||
this.aside.appendChild(instanceLinkArea.wrap);
|
||||
|
||||
const usernameArea = this.generateLabelInput("username",
|
||||
this.tls.username, this.tls.username_explica, "text", this.config.settings.username);
|
||||
this.aside.appendChild(usernameArea.wrap);
|
||||
|
||||
const mailArea = this.generateLabelInput("mail",
|
||||
this.tls.mail, this.tls.mail_explica, "email", this.config.settings.mail);
|
||||
this.aside.appendChild(mailArea.wrap);
|
||||
|
||||
const institutionIdArea = this.generateLabelInput("institutionId",
|
||||
this.tls.institution_id, this.tls.institution_id_explica, "number", this.config.settings.institution_id);
|
||||
this.aside.appendChild(institutionIdArea.wrap);
|
||||
|
||||
const tokenArea = this.generateLabelInput("token",
|
||||
this.tls.token, this.tls.token_explica, "text", this.config.settings.token);
|
||||
this.aside.appendChild(tokenArea.wrap);
|
||||
|
||||
const parserDiv = document.createElement("div");
|
||||
parserDiv.classList.add("label-input");
|
||||
|
||||
const parserLabel = document.createElement("label");
|
||||
parserLabel.setAttribute("for", "parserSelect");
|
||||
parserLabel.textContent = this.tls.parser;
|
||||
parserDiv.appendChild(parserLabel);
|
||||
const parserSelect = document.createElement("select");
|
||||
parserSelect.id = "parserSelect";
|
||||
|
||||
for (const entry of this.parserList) {
|
||||
const opt = document.createElement("option");
|
||||
opt.value = entry.title;
|
||||
opt.textContent = entry.title;
|
||||
if (entry.title === this.config.settings.parser) {
|
||||
opt.setAttribute("selected", "selected");
|
||||
}
|
||||
parserSelect.appendChild(opt);
|
||||
}
|
||||
|
||||
parserDiv.appendChild(parserSelect);
|
||||
|
||||
const parserHelp = document.createElement("span");
|
||||
parserHelp.classList.add("icon-help");
|
||||
parserHelp.title = this.tls.parser_explica;
|
||||
parserDiv.appendChild(parserHelp);
|
||||
|
||||
this.aside.appendChild(parserDiv);
|
||||
|
||||
const uploadFolderArea = this.generateLabelInput("upload-folder",
|
||||
this.tls.upload_directory, this.tls.upload_directory_explica, "text", this.config.settings.upload_directory);
|
||||
this.aside.appendChild(uploadFolderArea.wrap);
|
||||
|
||||
const visibleDivOuter = document.createElement("div");
|
||||
visibleDivOuter.classList.add("label-input");
|
||||
const visibleLabel = document.createElement("label");
|
||||
visibleLabel.setAttribute("for", "visible");
|
||||
visibleLabel.textContent = this.tls.publish_immediately;
|
||||
visibleDivOuter.appendChild(visibleLabel);
|
||||
|
||||
const visibleDiv = document.createElement("div");
|
||||
const visibleSwitch = document.createElement("div");
|
||||
visibleSwitch.classList.add("switch");
|
||||
|
||||
const visibleInput = document.createElement("input");
|
||||
visibleInput.type = "checkbox";
|
||||
if (this.config.settings.visible === true) {
|
||||
visibleInput.checked = "checked";
|
||||
console.log(visibleInput);
|
||||
}
|
||||
visibleSwitch.appendChild(visibleInput);
|
||||
|
||||
const visibleSlider = document.createElement("span");
|
||||
visibleSlider.classList.add("slider");
|
||||
visibleSlider.addEventListener('click', function() {
|
||||
visibleInput.checked = !visibleInput.checked;
|
||||
console.log(visibleInput);
|
||||
});
|
||||
visibleSwitch.appendChild(visibleSlider);
|
||||
|
||||
visibleDiv.appendChild(visibleSwitch);
|
||||
visibleDivOuter.appendChild(visibleDiv);
|
||||
|
||||
const visibleHelp = document.createElement("span");
|
||||
visibleHelp.classList.add("icon-help");
|
||||
visibleHelp.title = this.tls.publish_immediately_explica;
|
||||
visibleDivOuter.appendChild(visibleHelp);
|
||||
|
||||
this.aside.appendChild(visibleDivOuter);
|
||||
|
||||
// Additional settings
|
||||
this.aside.appendChild(this.generateTextElement("h3", this.tls.additional_settings));
|
||||
|
||||
const addSettingsArea = document.createElement("div");
|
||||
|
||||
const app = this;
|
||||
function generateAdditionalSettingsField(key, value) {
|
||||
|
||||
const line = document.createElement("div");
|
||||
line.classList.add("label-input");
|
||||
|
||||
const newKey = document.createElement("input");
|
||||
newKey.placeholder = app.tls.add_settings_key;
|
||||
newKey.required = "required";
|
||||
newKey.value = key;
|
||||
line.appendChild(newKey);
|
||||
|
||||
const newVal = document.createElement("input");
|
||||
newVal.placeholder = app.tls.add_settings_value;
|
||||
newVal.required = "required";
|
||||
newVal.value = value;
|
||||
line.appendChild(newVal);
|
||||
|
||||
const removeB = document.createElement("button");
|
||||
removeB.textContent = " x ";
|
||||
removeB.title = app.tls.remove;
|
||||
line.appendChild(removeB);
|
||||
|
||||
removeB.addEventListener('click', function() {
|
||||
line.parentElement.removeChild(line);
|
||||
});
|
||||
|
||||
return line;
|
||||
|
||||
}
|
||||
|
||||
if (this.config.settings.settings != undefined && this.config.settings.settings != null && this.config.settings.settings.length != 0) {
|
||||
for (let settingKey in this.config.settings.settings) {
|
||||
addSettingsArea.appendChild(generateAdditionalSettingsField(settingKey, this.config.settings.settings[settingKey]));
|
||||
}
|
||||
}
|
||||
|
||||
this.aside.appendChild(addSettingsArea);
|
||||
|
||||
const newSettingLine = document.createElement("form");
|
||||
newSettingLine.classList.add("label-input");
|
||||
|
||||
const newKey = document.createElement("input");
|
||||
newKey.placeholder = this.tls.add_settings_key;
|
||||
newKey.required = "required";
|
||||
newSettingLine.appendChild(newKey);
|
||||
|
||||
const newVal = document.createElement("input");
|
||||
newVal.placeholder = this.tls.add_settings_value;
|
||||
newVal.required = "required";
|
||||
newSettingLine.appendChild(newVal);
|
||||
|
||||
const newSubmitB = document.createElement("button");
|
||||
newSubmitB.type = "submit";
|
||||
newSubmitB.textContent = " > ";
|
||||
newSubmitB.title = app.tls.add;
|
||||
newSettingLine.appendChild(newSubmitB);
|
||||
|
||||
newSettingLine.addEventListener('submit', function(e) {
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
|
||||
addSettingsArea.appendChild(generateAdditionalSettingsField(newKey.value, newVal.value));
|
||||
|
||||
newKey.value = "";
|
||||
newVal.value = "";
|
||||
});
|
||||
|
||||
this.aside.appendChild(newSettingLine)
|
||||
|
||||
const updateB = document.createElement("button");
|
||||
updateB.textContent = this.tls.save_update;
|
||||
updateB.classList.add("updateB");
|
||||
this.aside.appendChild(updateB);
|
||||
|
||||
updateB.addEventListener('click', async function() {
|
||||
|
||||
let toSave = {
|
||||
instance: instanceLinkArea.input.value,
|
||||
username: usernameArea.input.value,
|
||||
mail: mailArea.input.value,
|
||||
token: tokenArea.input.value,
|
||||
institution_id: parseInt(institutionIdArea.input.value),
|
||||
parser: parserSelect.value,
|
||||
upload_directory: uploadFolderArea.input.value,
|
||||
visible: visibleInput.checked,
|
||||
settings: {}
|
||||
};
|
||||
|
||||
for (const l of addSettingsArea.children) {
|
||||
toSave.settings[l.children[0].value] = l.children[1].value;
|
||||
}
|
||||
|
||||
const response = await window.fetch('/update-settings', {
|
||||
method: 'POST', cache: 'no-cache',
|
||||
credentials: 'same-origin',
|
||||
headers: {
|
||||
'Content-Type': 'application/x-www-form-urlencoded'
|
||||
},
|
||||
body: "settings=" + encodeURIComponent(JSON.stringify(toSave, null, 2))
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
console.log("Failed to save");
|
||||
window.alert("Failed to store.");
|
||||
}
|
||||
|
||||
const json = await response.json();
|
||||
|
||||
if (json.success === true) {
|
||||
location.reload();
|
||||
}
|
||||
else {
|
||||
alert("Error:\n" + json.error);
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
generateMain() {
|
||||
|
||||
this.main.appendChild(this.generateTextElement("h2", this.tls.uploadable_files));
|
||||
|
||||
// Metadata
|
||||
const metadataSec = document.createElement("section");
|
||||
|
||||
metadataSec.appendChild(this.generateTextElement("h3", this.tls.metadata_files));
|
||||
const metadataList = document.createElement("div");
|
||||
metadataList.classList.add("upload-file-list");
|
||||
|
||||
for (const filename of this.uploadableFiles.metadata) {
|
||||
const fileline = document.createElement("span");
|
||||
fileline.classList.add("icon-file");
|
||||
fileline.textContent = filename;
|
||||
metadataList.appendChild(fileline);
|
||||
}
|
||||
|
||||
metadataSec.appendChild(metadataList);
|
||||
|
||||
this.main.appendChild(metadataSec);
|
||||
|
||||
// Media
|
||||
const mediaSec = document.createElement("section");
|
||||
|
||||
mediaSec.appendChild(this.generateTextElement("h3", this.tls.media_files));
|
||||
const mediaList = document.createElement("div");
|
||||
mediaList.classList.add("upload-file-list");
|
||||
|
||||
for (const filename of this.uploadableFiles.media_files) {
|
||||
const fileline = document.createElement("span");
|
||||
fileline.classList.add("icon-file");
|
||||
fileline.textContent = filename;
|
||||
mediaList.appendChild(fileline);
|
||||
}
|
||||
|
||||
mediaSec.appendChild(mediaList);
|
||||
this.main.appendChild(mediaSec);
|
||||
|
||||
}
|
||||
|
||||
manageUpload() {
|
||||
|
||||
const transferOverlay = document.createElement("div");
|
||||
transferOverlay.id = "transfer-overlay";
|
||||
transferOverlay.classList.add("transfer-overlay");
|
||||
const hl = document.createElement("div");
|
||||
hl.classList.add("transfer-overlay-hl");
|
||||
hl.appendChild(this.generateTextElement("h3", this.tls.upload));
|
||||
|
||||
const closeB = document.createElement("span");
|
||||
closeB.classList.add("overlay-close");
|
||||
hl.appendChild(closeB);
|
||||
|
||||
closeB.addEventListener('click', function() { location.reload(); });
|
||||
// closeB.addEventListener('click', function() { transferOverlay.parentElement.removeChild(transferOverlay); });
|
||||
|
||||
transferOverlay.appendChild(hl);
|
||||
|
||||
const transferMsgs = document.createElement("div");
|
||||
transferMsgs.classList.add("transfer-msgs");
|
||||
transferOverlay.appendChild(transferMsgs);
|
||||
|
||||
this.wrap.appendChild(transferOverlay);
|
||||
|
||||
const iframe = document.createElement("iframe");
|
||||
iframe.src = "/trigger-upload";
|
||||
transferOverlay.appendChild(iframe);
|
||||
|
||||
}
|
||||
|
||||
generateActionsMenu() {
|
||||
|
||||
if (this.uploadableFiles.metadata.length === 0 && this.uploadableFiles.media_files.length === 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const uploadTrigger = document.createElement("span");
|
||||
uploadTrigger.textContent = this.tls.upload;
|
||||
this.actionsArea.appendChild(uploadTrigger);
|
||||
|
||||
const app = this;
|
||||
uploadTrigger.addEventListener('click', function() {
|
||||
app.manageUpload();
|
||||
}, {once: true});
|
||||
|
||||
// Handle next auto upload
|
||||
const nextAutoUpload = document.createElement("span");
|
||||
const startTimeStr = this.tls.next_scheduled_check + ": ";
|
||||
this.actionsArea.appendChild(nextAutoUpload);
|
||||
|
||||
const options1 = {
|
||||
year: 'numeric',
|
||||
month: '2-digit',
|
||||
day: '2-digit',
|
||||
hour: '2-digit',
|
||||
minute: '2-digit',
|
||||
};
|
||||
|
||||
const dateTimeFormat1 = new Intl.DateTimeFormat(this.lang, options1);
|
||||
const nextUploadTime = Date.parse(this.config.next_auto_upload);
|
||||
const now = new Date();
|
||||
|
||||
setInterval(function() {
|
||||
const diffMs = nextUploadTime - now;
|
||||
const diffMins = Math.round((diffMs % 86400000) / 60000); // minutes
|
||||
nextAutoUpload.textContent = startTimeStr + dateTimeFormat1.format(nextUploadTime) + " (in " + diffMins + " mins)";
|
||||
}, 60);
|
||||
|
||||
// Version
|
||||
const vSpan = document.createElement("a");
|
||||
vSpan.textContent = this.tls.version + " " + this.config.version;
|
||||
if (this.config.update_available === true) {
|
||||
vSpan.style.color = "red";
|
||||
vSpan.href = "https://gitea.armuli.eu/museum-digital/museum-digital-webdav-uploader/releases";
|
||||
}
|
||||
this.actionsArea.appendChild(vSpan)
|
||||
|
||||
}
|
||||
|
||||
// Provides a sidebar entry for describing the parser
|
||||
generateParserDesc() {
|
||||
|
||||
for (const parser of this.parserList) {
|
||||
if (parser.title == this.config.settings.parser) {
|
||||
|
||||
const aside = document.createElement("div");
|
||||
aside.classList.add("sec-aside");
|
||||
|
||||
aside.appendChild(this.generateTextElement("h3", this.tls.parser + ": " + parser.title));
|
||||
const div = document.createElement("div");
|
||||
div.classList.add("parser-desc");
|
||||
|
||||
const desc = document.createElement("p");
|
||||
desc.textContent = parser.comment;
|
||||
div.appendChild(desc);
|
||||
|
||||
aside.appendChild(div);
|
||||
|
||||
this.wrap.appendChild(aside);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
render() {
|
||||
|
||||
if (this.config.setup_required === true) {
|
||||
wrap.classList.add("setup-required");
|
||||
this.generateSidebar();
|
||||
}
|
||||
else {
|
||||
this.generateSidebar();
|
||||
this.generateMain();
|
||||
this.generateActionsMenu();
|
||||
|
||||
this.generateParserDesc();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
setupFromApis() {
|
||||
|
||||
|
||||
const app = this;
|
||||
let done = 0;
|
||||
|
||||
function wrapFinish() {
|
||||
if (done === 4) {
|
||||
app.render();
|
||||
}
|
||||
}
|
||||
|
||||
window.fetch('/get-settings', {method: 'GET', cache: 'no-cache', credentials: 'same-origin'})
|
||||
.then(function(response) { return response.json(); })
|
||||
.then(function(elements) {
|
||||
app.config = elements;
|
||||
done++;
|
||||
wrapFinish();
|
||||
});
|
||||
window.fetch('/list-parsers', {method: 'GET', cache: 'no-cache', credentials: 'same-origin'})
|
||||
.then(function(response) { return response.json(); })
|
||||
.then(function(elements) {
|
||||
app.parserList = elements;
|
||||
done++;
|
||||
wrapFinish();
|
||||
});
|
||||
window.fetch('/list-uploadable', {method: 'GET', cache: 'no-cache', credentials: 'same-origin'})
|
||||
.then(function(response) { return response.json(); })
|
||||
.then(function(elements) {
|
||||
app.uploadableFiles = elements;
|
||||
done++;
|
||||
wrapFinish();
|
||||
});
|
||||
window.fetch('/get-translations?lang=' + encodeURIComponent(this.lang), {method: 'GET', cache: 'no-cache', credentials: 'same-origin'})
|
||||
.then(function(response) { return response.json(); })
|
||||
.then(function(elements) {
|
||||
app.tls = elements.webdav_uploader;
|
||||
done++;
|
||||
wrapFinish();
|
||||
});
|
||||
}
|
||||
|
||||
constructor() {
|
||||
|
||||
this.wrap = document.getElementById("wrap");
|
||||
this.lang = navigator.language.substring(0, 2)
|
||||
if (["de", "en"].includes(this.lang) === false) {
|
||||
this.lang = "en";
|
||||
}
|
||||
|
||||
this.aside = document.createElement("aside");
|
||||
this.main = document.createElement("main");
|
||||
this.actionsArea = document.getElementById("actions");
|
||||
|
||||
this.wrap.appendChild(this.aside);
|
||||
this.wrap.appendChild(this.main);
|
||||
|
||||
this.setupFromApis();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
new App();
|
55
src/webui/headers.go
Normal file
55
src/webui/headers.go
Normal file
@@ -0,0 +1,55 @@
|
||||
package webui
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
)
|
||||
|
||||
// Sets generally useful HTTP headers, e.g. limiting frame-options.
|
||||
func setDefaultHeaders(w http.ResponseWriter) {
|
||||
|
||||
w.Header().Set("X-Content-Type-Options", "nosniff")
|
||||
w.Header().Set("X-Frame-Options", "SAMEORIGIN")
|
||||
w.Header().Set("X-XSS-Protection", "1; mode=block")
|
||||
w.Header().Set("Access-Control-Allow-Methods", "GET, POST, OPTIONS")
|
||||
w.Header().Set("Access-Control-Allow-Origin", "*")
|
||||
w.Header().Set("Access-Control-Expose-Headers", "Content-Type")
|
||||
// w.Header().Set("Strict-Transport-Security", "max-age=63072000")
|
||||
|
||||
}
|
||||
|
||||
// Sets the HTTP headers expected to be returned when serving HTML pages.
|
||||
func setHeadersForHtml(w http.ResponseWriter) {
|
||||
setDefaultHeaders(w)
|
||||
w.Header().Set("Content-Security-Policy", "default-src 'self'; font-src 'self'; object-src 'none'; frame-src 'self'; frame-ancestors 'none'; base-uri 'none'; script-src 'self'; style-src 'self' 'unsafe-inline'")
|
||||
}
|
||||
|
||||
// Sets the HTTP headers expected to be returned when serving JSON.
|
||||
func setHeadersForJson(w http.ResponseWriter) {
|
||||
setDefaultHeaders(w)
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
}
|
||||
|
||||
// Sets the HTTP headers expected to be returned when serving CSS files.
|
||||
func setHeadersForCss(w http.ResponseWriter) {
|
||||
setDefaultHeaders(w)
|
||||
w.Header().Set("Content-Type", "text/css")
|
||||
}
|
||||
|
||||
// Sets the HTTP headers expected to be returned when serving JS files.
|
||||
func setHeadersForJs(w http.ResponseWriter) {
|
||||
setDefaultHeaders(w)
|
||||
w.Header().Set("Content-Type", "text/javascript")
|
||||
}
|
||||
|
||||
// Sets the HTTP headers expected to be returned when serving SVG files.
|
||||
func setHeadersForSvg(w http.ResponseWriter) {
|
||||
setDefaultHeaders(w)
|
||||
w.Header().Set("Content-Type", "image/svg+xml")
|
||||
}
|
||||
func setHeadersForEventStream(w http.ResponseWriter) {
|
||||
setDefaultHeaders(w)
|
||||
w.Header().Set("X-Accel-Buffering", "no")
|
||||
w.Header().Set("Content-Type", "text/event-stream")
|
||||
w.Header().Set("Cache-Control", "no-cache")
|
||||
w.Header().Set("Connection", "keep-alive")
|
||||
}
|
39
src/webui/serveApiGetSettings.go
Normal file
39
src/webui/serveApiGetSettings.go
Normal file
@@ -0,0 +1,39 @@
|
||||
package webui
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"gitea.armuli.eu/museum-digital/museum-digital-webdav-uploader/src/configloader"
|
||||
"gitea.armuli.eu/museum-digital/museum-digital-webdav-uploader/src/meta"
|
||||
)
|
||||
|
||||
type getSettingsApiResponse struct {
|
||||
Version string `json:"version"`
|
||||
SetupRequired bool `json:"setup_required"`
|
||||
Settings configloader.MDWebDavUploaderConfig `json:"settings"`
|
||||
NextAutoUpload string `json:"next_auto_upload"`
|
||||
UpdateAvailable bool `json:"update_available"`
|
||||
}
|
||||
|
||||
// Generates the API output for listing current settings.
|
||||
func serveApiGetSettings(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
var nextAutoUpOut string
|
||||
nextAutoUp, err := scheduledUpload.NextRun()
|
||||
if err != nil {
|
||||
nextAutoUpOut = "";
|
||||
} else {
|
||||
nextAutoUpOut = nextAutoUp.Format("2006-01-02 15:04:05")
|
||||
}
|
||||
|
||||
setHeadersForJson(w)
|
||||
output := getSettingsApiResponse{SetupRequired: setupRequired, Settings: config, Version: meta.GetVersion(), NextAutoUpload: nextAutoUpOut, UpdateAvailable: updateAvailable}
|
||||
|
||||
outputJson, encodeErr := json.Marshal(output)
|
||||
if encodeErr != nil {
|
||||
panic("Failed to create JSON")
|
||||
}
|
||||
|
||||
fmt.Fprint(w, string(outputJson))
|
||||
}
|
32
src/webui/serveApiGetTranslations.go
Normal file
32
src/webui/serveApiGetTranslations.go
Normal file
@@ -0,0 +1,32 @@
|
||||
package webui
|
||||
|
||||
import (
|
||||
_ "embed"
|
||||
"fmt"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
type tlRaw struct {
|
||||
webdav_uploader map[string]string `json:"webdav_uploader"`
|
||||
}
|
||||
|
||||
//go:embed translation-json/webdav-uploader/de/webdav_uploader.json
|
||||
var rawTlsDe string
|
||||
//go:embed translation-json/webdav-uploader/en/webdav_uploader.json
|
||||
var rawTlsEn string
|
||||
|
||||
// Retrieves translation variables in the given language.
|
||||
func serveApiGetTranslations(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
var rawTls string
|
||||
if r.URL.Query().Get("lang") == "de" {
|
||||
rawTls = rawTlsDe
|
||||
} else {
|
||||
rawTls = rawTlsEn
|
||||
}
|
||||
|
||||
setHeadersForJson(w)
|
||||
|
||||
fmt.Fprint(w, rawTls)
|
||||
|
||||
}
|
22
src/webui/serveApiListParsers.go
Normal file
22
src/webui/serveApiListParsers.go
Normal file
@@ -0,0 +1,22 @@
|
||||
package webui
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"gitea.armuli.eu/museum-digital/museum-digital-webdav-uploader/src/configloader"
|
||||
)
|
||||
|
||||
// Provides the JSON API for listing all available parsers.
|
||||
func serveApiListParsers(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
setHeadersForJson(w)
|
||||
|
||||
outputJson, encodeErr := json.Marshal(configloader.ListParsers())
|
||||
if encodeErr != nil {
|
||||
panic("Failed to create JSON")
|
||||
}
|
||||
|
||||
fmt.Fprint(w, string(outputJson))
|
||||
|
||||
}
|
36
src/webui/serveApiListUploadable.go
Normal file
36
src/webui/serveApiListUploadable.go
Normal file
@@ -0,0 +1,36 @@
|
||||
package webui
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"gitea.armuli.eu/museum-digital/museum-digital-webdav-uploader/src/uploadsrcdir"
|
||||
)
|
||||
|
||||
type listUploadableApiResponse struct {
|
||||
Metadata []string `json:"metadata"`
|
||||
MediaFiles []string `json:"media_files"`
|
||||
}
|
||||
|
||||
// Provides the JSON API for listing all metadata and media files that
|
||||
// are currently listed to be uploaded.
|
||||
func serveApiListUploadable(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
setHeadersForJson(w)
|
||||
|
||||
var output listUploadableApiResponse
|
||||
if setupRequired == true {
|
||||
output = listUploadableApiResponse{Metadata: []string{}, MediaFiles: []string{}}
|
||||
} else {
|
||||
uploadableMetadata, uploadableMedia := uploadsrcdir.GetUploadableFiles(config)
|
||||
output = listUploadableApiResponse{Metadata: uploadableMetadata, MediaFiles: uploadableMedia}
|
||||
}
|
||||
|
||||
outputJson, encodeErr := json.Marshal(output)
|
||||
if encodeErr != nil {
|
||||
panic("Failed to create JSON")
|
||||
}
|
||||
|
||||
fmt.Fprint(w, string(outputJson))
|
||||
|
||||
}
|
55
src/webui/serveApiTriggerUpload.go
Normal file
55
src/webui/serveApiTriggerUpload.go
Normal file
@@ -0,0 +1,55 @@
|
||||
package webui
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"gitea.armuli.eu/museum-digital/museum-digital-webdav-uploader/src/uploadsrcdir"
|
||||
"gitea.armuli.eu/museum-digital/museum-digital-webdav-uploader/src/webdavupload"
|
||||
)
|
||||
|
||||
// Provides the API logic for uploading files.
|
||||
func serveApiTriggerUpload(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
fmt.Println("Upload requested")
|
||||
setHeadersForEventStream(w)
|
||||
w.(http.Flusher).Flush()
|
||||
|
||||
fmt.Fprint(w, "Getting list of uploadable files\n")
|
||||
w.(http.Flusher).Flush()
|
||||
uploadableMetadata, uploadableMedia := uploadsrcdir.GetUploadableFiles(config)
|
||||
|
||||
// If there are no files to upload, do nothing
|
||||
if len(uploadableMetadata) == 0 && len(uploadableMedia) == 0 {
|
||||
return
|
||||
}
|
||||
|
||||
fmt.Fprint(w, "Connecting to WebDAV share\n")
|
||||
w.(http.Flusher).Flush()
|
||||
c := webdavupload.GetWebdavClient(config)
|
||||
fmt.Fprint(w, "Connected\n")
|
||||
w.(http.Flusher).Flush()
|
||||
|
||||
if webdavupload.CheckRemoteIsFree(c) == false {
|
||||
fmt.Println("The remote is currently occupied (very recent files, or an import config is currently waiting to be processed, are present).")
|
||||
return
|
||||
}
|
||||
|
||||
// Upload the files
|
||||
if len(uploadableMetadata) > 0 {
|
||||
fmt.Fprint(w, "Uploading metadata files\n")
|
||||
w.(http.Flusher).Flush()
|
||||
webdavupload.UploadMetadataFiles(c, w, uploadableMetadata)
|
||||
webdavupload.BatchUnlink(w, uploadableMetadata)
|
||||
}
|
||||
if len(uploadableMedia) > 0 {
|
||||
fmt.Fprint(w, "Uploading media files\n")
|
||||
webdavupload.UploadMediaFiles(c, w, uploadableMedia)
|
||||
webdavupload.BatchUnlink(w, uploadableMedia)
|
||||
}
|
||||
|
||||
fmt.Fprint(w, "Generating and uploading import configuration\n")
|
||||
webdavupload.SetImportConfigToTheRemote(c, config)
|
||||
fmt.Fprint(w, "DONE\n")
|
||||
w.(http.Flusher).Flush()
|
||||
|
||||
}
|
59
src/webui/serveApiUpdateSettings.go
Normal file
59
src/webui/serveApiUpdateSettings.go
Normal file
@@ -0,0 +1,59 @@
|
||||
package webui
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"gitea.armuli.eu/museum-digital/museum-digital-webdav-uploader/src/configloader"
|
||||
)
|
||||
|
||||
type updateSettingsResponse struct {
|
||||
Success bool `json:"success"`
|
||||
ValidationError string `json:"error"`
|
||||
}
|
||||
|
||||
// Provides the API for updating the general configuration.
|
||||
func serveApiUpdateSettings(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
setHeadersForJson(w)
|
||||
|
||||
// Parse POST data
|
||||
parseErr := r.ParseForm()
|
||||
if parseErr != nil {
|
||||
fmt.Println("Failed to load form data")
|
||||
return
|
||||
}
|
||||
|
||||
// Load new config from a POST variable 'settings' that provides the full
|
||||
// settings as a JSON-encoded string.
|
||||
rawInputConfig := r.PostForm.Get("settings")
|
||||
var newConfig configloader.MDWebDavUploaderConfig
|
||||
unmarshalErr := json.Unmarshal([]byte(rawInputConfig), &newConfig)
|
||||
if unmarshalErr != nil {
|
||||
fmt.Fprint(w, "{\"success\": false, \"error\": \"Invalid input JSON\"}")
|
||||
return
|
||||
}
|
||||
|
||||
// Attempt to store the new settings. Validation takes place while storing
|
||||
var output updateSettingsResponse
|
||||
validationErr := configloader.StoreConfigToFile(newConfig, "")
|
||||
if validationErr == nil {
|
||||
output = updateSettingsResponse{Success: true, ValidationError: ""}
|
||||
|
||||
// Reload config
|
||||
config, setupRequired, _ = configloader.LoadFromFile("")
|
||||
|
||||
} else {
|
||||
output = updateSettingsResponse{Success: false, ValidationError: validationErr.Error()}
|
||||
}
|
||||
|
||||
// Format response in JSON, then print it
|
||||
outputJson, encodeErr := json.Marshal(output)
|
||||
if encodeErr != nil {
|
||||
panic("Failed to create JSON")
|
||||
}
|
||||
|
||||
fmt.Fprint(w, string(outputJson))
|
||||
|
||||
|
||||
}
|
16
src/webui/serveAppShell.go
Normal file
16
src/webui/serveAppShell.go
Normal file
@@ -0,0 +1,16 @@
|
||||
package webui
|
||||
|
||||
import (
|
||||
_ "embed"
|
||||
"fmt"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
//go:embed assets/index.htm
|
||||
var indexHtml string
|
||||
|
||||
// Serves the app shell. Contents are managed via APIs and JS.
|
||||
func serveAppShell(w http.ResponseWriter, r *http.Request) {
|
||||
setHeadersForHtml(w)
|
||||
fmt.Fprint(w, indexHtml)
|
||||
}
|
16
src/webui/serveCss.go
Normal file
16
src/webui/serveCss.go
Normal file
@@ -0,0 +1,16 @@
|
||||
package webui
|
||||
|
||||
import (
|
||||
_ "embed"
|
||||
"fmt"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
//go:embed assets/md-uploader.css
|
||||
var webuiCss string
|
||||
|
||||
// Serves the style sheet of the web app.
|
||||
func serveCss(w http.ResponseWriter, r *http.Request) {
|
||||
setHeadersForCss(w)
|
||||
fmt.Fprint(w, webuiCss)
|
||||
}
|
16
src/webui/serveJs.go
Normal file
16
src/webui/serveJs.go
Normal file
@@ -0,0 +1,16 @@
|
||||
package webui
|
||||
|
||||
import (
|
||||
_ "embed"
|
||||
"fmt"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
//go:embed assets/md-uploader.js
|
||||
var webuiJs string
|
||||
|
||||
// Serves the JS for the web app.
|
||||
func serveJs(w http.ResponseWriter, r *http.Request) {
|
||||
setHeadersForJs(w)
|
||||
fmt.Fprint(w, webuiJs)
|
||||
}
|
16
src/webui/serveLogo.go
Normal file
16
src/webui/serveLogo.go
Normal file
@@ -0,0 +1,16 @@
|
||||
package webui
|
||||
|
||||
import (
|
||||
_ "embed"
|
||||
"fmt"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
//go:embed assets/logo-md-code-black.svg
|
||||
var logoSvg string
|
||||
|
||||
// Serves the logo.
|
||||
func serveLogo(w http.ResponseWriter, r *http.Request) {
|
||||
setHeadersForSvg(w)
|
||||
fmt.Fprint(w, logoSvg)
|
||||
}
|
126
src/webui/server.go
Normal file
126
src/webui/server.go
Normal file
@@ -0,0 +1,126 @@
|
||||
package webui
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"net/http"
|
||||
"os/exec"
|
||||
"runtime"
|
||||
"time"
|
||||
"github.com/go-co-op/gocron/v2"
|
||||
"gitea.armuli.eu/museum-digital/museum-digital-webdav-uploader/src/cli"
|
||||
"gitea.armuli.eu/museum-digital/museum-digital-webdav-uploader/src/configloader"
|
||||
"gitea.armuli.eu/museum-digital/museum-digital-webdav-uploader/src/meta"
|
||||
)
|
||||
|
||||
var config configloader.MDWebDavUploaderConfig
|
||||
var setupRequired bool
|
||||
var scheduler gocron.Scheduler
|
||||
var scheduledUpload gocron.Job
|
||||
var updateAvailable bool
|
||||
|
||||
// Opens the application in the default browser.
|
||||
func openInBrowser(port string) {
|
||||
|
||||
var err error
|
||||
target := "localhost:" + port
|
||||
switch runtime.GOOS {
|
||||
case "linux":
|
||||
err = exec.Command("xdg-open", target).Start()
|
||||
case "windows":
|
||||
err = exec.Command("rundll32", "url.dll,FileProtocolHandler", target).Start()
|
||||
case "darwin":
|
||||
err = exec.Command("open", target).Start()
|
||||
default:
|
||||
err = fmt.Errorf("unsupported platform")
|
||||
}
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func scheduleUploads() {
|
||||
|
||||
s, err := gocron.NewScheduler()
|
||||
defer func() { _ = s.Shutdown() }()
|
||||
|
||||
if err != nil {
|
||||
panic("Failed to set up scheduler")
|
||||
}
|
||||
|
||||
j, jobErr := s.NewJob(
|
||||
gocron.DurationJob(
|
||||
3 * time.Hour,
|
||||
),
|
||||
gocron.NewTask(
|
||||
func() {
|
||||
fmt.Println("Checking if an upload should be done")
|
||||
fmt.Println(time.Now().Format("20060102150405"))
|
||||
cli.Upload()
|
||||
},
|
||||
),
|
||||
)
|
||||
if jobErr != nil {
|
||||
panic("Failed to set up scheduler job")
|
||||
}
|
||||
|
||||
scheduledUpload = j
|
||||
s.Start()
|
||||
select {}
|
||||
|
||||
}
|
||||
|
||||
// Checks if a new update is available. If that can be confirmed, set updateAvailable
|
||||
// to true.
|
||||
func checkUpdateAvailable() {
|
||||
|
||||
output, err := meta.CheckVersionIsUpToDate()
|
||||
// If the RSS stream could not be fetched or parsed, don't say anything
|
||||
if err != nil || output.Title == "" {
|
||||
updateAvailable = false
|
||||
} else {
|
||||
updateAvailable = true
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Sets up the server and manages routing.
|
||||
func Run() {
|
||||
|
||||
checkUpdateAvailable()
|
||||
|
||||
config, setupRequired, _ = configloader.LoadFromFile("")
|
||||
|
||||
// Bind callable URLs
|
||||
http.HandleFunc("/", serveAppShell) // Serve app shell
|
||||
http.HandleFunc("/get-settings", serveApiGetSettings) // API for listing current settings
|
||||
http.HandleFunc("/get-translations", serveApiGetTranslations) // API for listing current settings
|
||||
http.HandleFunc("/list-uploadable", serveApiListUploadable) // API to list uploadable files
|
||||
http.HandleFunc("/list-parsers", serveApiListParsers) // API to list available parsers.
|
||||
http.HandleFunc("/update-settings", serveApiUpdateSettings) // API for updating settings
|
||||
http.HandleFunc("/trigger-upload", serveApiTriggerUpload) // Serve page for specific files
|
||||
http.HandleFunc("/md-uploader.css", serveCss) // Main CSS file.
|
||||
http.HandleFunc("/md-uploader.js", serveJs) // Main JS file.
|
||||
http.HandleFunc("/logo.svg", serveLogo) // Logo.
|
||||
|
||||
port := "8080"
|
||||
go func() {
|
||||
|
||||
// Set port to listen on
|
||||
fmt.Println("Server started at port " + string(port))
|
||||
err := http.ListenAndServe(":"+port, nil)
|
||||
if err != nil {
|
||||
log.Fatal("ListenAndServe: ", err)
|
||||
}
|
||||
|
||||
}();
|
||||
go func() {
|
||||
time.Sleep(5)
|
||||
openInBrowser(port)
|
||||
}();
|
||||
go scheduleUploads()
|
||||
|
||||
select{}
|
||||
|
||||
}
|
1
src/webui/translation-json
Submodule
1
src/webui/translation-json
Submodule
Submodule src/webui/translation-json added at 89deadcad0
Reference in New Issue
Block a user