Compare commits
17 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d7306d3fe9 | ||
|
|
20dc64834a | ||
|
|
16faf90989 | ||
|
|
f320d28f37 | ||
|
|
1a1bff7287 | ||
|
|
9aedb0280b | ||
|
|
75e0d16ac5 | ||
|
|
b174012e5a | ||
|
|
c2ab9251c6 | ||
|
|
d0b2601f80 | ||
|
|
f0e431ff7c | ||
|
|
29838b1028 | ||
|
|
d98dfadf6c | ||
|
|
24a2811533 | ||
|
|
8ba031efe5 | ||
|
|
bec1c9b3b6 | ||
|
|
899d2233af |
5
.gitignore
vendored
5
.gitignore
vendored
@@ -14,3 +14,8 @@
|
||||
/WeddingShare/wwwroot/uploads/*
|
||||
!/WeddingShare/wwwroot/uploads/default
|
||||
/WeddingShare/wwwroot/uploads/default/*
|
||||
/release notes
|
||||
/WeddingShare/weddingshare.db
|
||||
/WeddingShare/wedding-share.db
|
||||
/WeddingShare/config/wedding-share.db
|
||||
/WeddingShare/wwwroot/thumbnails
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
image: mcr.microsoft.com/dotnet/sdk:latest
|
||||
|
||||
stages:
|
||||
- test
|
||||
- build
|
||||
- push
|
||||
- release
|
||||
@@ -22,13 +23,36 @@ cache:
|
||||
before_script:
|
||||
- 'docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY'
|
||||
|
||||
test:
|
||||
stage: test
|
||||
script:
|
||||
- 'dotnet restore'
|
||||
- 'dotnet test'
|
||||
|
||||
build:
|
||||
stage: build
|
||||
script:
|
||||
- 'docker build -t $CI_REGISTRY_IMAGE:dev -t $CI_REGISTRY_IMAGE:$CI_COMMIT_SHORT_SHA -f WeddingShare/Dockerfile .'
|
||||
- 'docker push $CI_REGISTRY_IMAGE:dev'
|
||||
- 'docker push $CI_REGISTRY_IMAGE:$CI_COMMIT_SHORT_SHA'
|
||||
needs:
|
||||
- test
|
||||
|
||||
push_pre_release:
|
||||
variables:
|
||||
GIT_STRATEGY: none
|
||||
stage: push
|
||||
only:
|
||||
- /^(prerel|rc|release)-[0-9]+\.[0-9]+\.[0-9]+$/
|
||||
script:
|
||||
- 'docker pull $CI_REGISTRY_IMAGE:$CI_COMMIT_SHORT_SHA'
|
||||
- 'docker tag $CI_REGISTRY_IMAGE:$CI_COMMIT_SHORT_SHA $CI_REGISTRY_IMAGE:$CI_COMMIT_BRANCH'
|
||||
- 'docker push $CI_REGISTRY_IMAGE:$CI_COMMIT_BRANCH'
|
||||
- 'docker tag $CI_REGISTRY_IMAGE:$CI_COMMIT_SHORT_SHA $CI_REGISTRY_IMAGE:pre_release'
|
||||
- 'docker push $CI_REGISTRY_IMAGE:pre_release'
|
||||
needs:
|
||||
- build
|
||||
|
||||
push_latest:
|
||||
variables:
|
||||
GIT_STRATEGY: none
|
||||
@@ -40,6 +64,8 @@ push_latest:
|
||||
- 'docker pull $CI_REGISTRY_IMAGE:$CI_COMMIT_SHORT_SHA'
|
||||
- 'docker tag $CI_REGISTRY_IMAGE:$CI_COMMIT_SHORT_SHA $CI_REGISTRY_IMAGE:latest'
|
||||
- 'docker push $CI_REGISTRY_IMAGE:latest'
|
||||
needs:
|
||||
- build
|
||||
|
||||
push_tag:
|
||||
variables:
|
||||
@@ -51,6 +77,8 @@ push_tag:
|
||||
- 'docker pull $CI_REGISTRY_IMAGE:$CI_COMMIT_SHORT_SHA'
|
||||
- 'docker tag $CI_REGISTRY_IMAGE:$CI_COMMIT_SHORT_SHA $CI_REGISTRY_IMAGE:$CI_COMMIT_REF_NAME'
|
||||
- 'docker push $CI_REGISTRY_IMAGE:$CI_COMMIT_REF_NAME'
|
||||
needs:
|
||||
- build
|
||||
|
||||
push_docker_hub:
|
||||
variables:
|
||||
@@ -64,4 +92,6 @@ push_docker_hub:
|
||||
- 'docker tag $CI_REGISTRY_IMAGE:latest $DOCKERHUB_USERNAME/wedding_share:latest'
|
||||
- 'docker push $DOCKERHUB_USERNAME/wedding_share:latest'
|
||||
- 'docker tag $CI_REGISTRY_IMAGE:latest $DOCKERHUB_USERNAME/wedding_share:$CI_COMMIT_REF_NAME'
|
||||
- 'docker push $DOCKERHUB_USERNAME/wedding_share:$CI_COMMIT_REF_NAME'
|
||||
- 'docker push $DOCKERHUB_USERNAME/wedding_share:$CI_COMMIT_REF_NAME'
|
||||
needs:
|
||||
- build
|
||||
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. <https://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 <https://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:
|
||||
|
||||
<program> Copyright (C) <year> <name of author>
|
||||
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
|
||||
<https://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
|
||||
<https://www.gnu.org/licenses/why-not-lgpl.html>.
|
||||
2
WeddingShare.UnitTests/GlobalUsings.cs
Normal file
2
WeddingShare.UnitTests/GlobalUsings.cs
Normal file
@@ -0,0 +1,2 @@
|
||||
global using NUnit.Framework;
|
||||
global using NSubstitute;
|
||||
14
WeddingShare.UnitTests/Helpers/ConfigurationHelper.cs
Normal file
14
WeddingShare.UnitTests/Helpers/ConfigurationHelper.cs
Normal file
@@ -0,0 +1,14 @@
|
||||
using Microsoft.Extensions.Configuration;
|
||||
|
||||
namespace WeddingShare.UnitTests.Helpers
|
||||
{
|
||||
internal class ConfigurationHelper
|
||||
{
|
||||
public static IConfiguration MockConfiguration(IDictionary<string, string?> settings)
|
||||
{
|
||||
return new ConfigurationBuilder()
|
||||
.AddInMemoryCollection(settings ?? new Dictionary<string, string?>())
|
||||
.Build();
|
||||
}
|
||||
}
|
||||
}
|
||||
39
WeddingShare.UnitTests/Tests/Extensions/StringExtensions.cs
Normal file
39
WeddingShare.UnitTests/Tests/Extensions/StringExtensions.cs
Normal file
@@ -0,0 +1,39 @@
|
||||
using WeddingShare.Extensions;
|
||||
|
||||
namespace WeddingShare.UnitTests.Tests.Helpers
|
||||
{
|
||||
public class StringExtensionsTests
|
||||
{
|
||||
public StringExtensionsTests()
|
||||
{
|
||||
}
|
||||
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
}
|
||||
|
||||
[TestCase("abcdefgh", new [] { "g" }, "+", "abcdef+h")]
|
||||
[TestCase("abcdefgh", new [] { "b", "e" }, "-", "a-cd-fgh")]
|
||||
[TestCase("abcdefgh", new [] { "bc", "e" }, "-", "a-d-fgh")]
|
||||
[TestCase("abcdefgeh", new [] { "bc", "e" }, "$", "a$d$fg$h")]
|
||||
[TestCase("abcdefgeh", new[] { "ee", "z" }, "$", "abcdefgeh")]
|
||||
public void StringExtensions_Replace(string input, string[] oldChars, string newChar, string expected)
|
||||
{
|
||||
var actual = input.Replace(oldChars, newChar);
|
||||
Assert.That(actual, Is.EqualTo(expected));
|
||||
}
|
||||
|
||||
[TestCase("abcdefge", "c", "abdefge")]
|
||||
[TestCase("abcdefge", "cd", "abefge")]
|
||||
[TestCase("abcdefge", "def", "abcge")]
|
||||
[TestCase("abcdefge", "e", "abcdfg")]
|
||||
[TestCase("abcdefg", "g", "abcdef")]
|
||||
[TestCase("abcdefg", "a", "bcdefg")]
|
||||
public void StringExtensions_Remove(string input, string value, string expected)
|
||||
{
|
||||
var actual = input.Remove(value);
|
||||
Assert.That(actual, Is.EqualTo(expected));
|
||||
}
|
||||
}
|
||||
}
|
||||
165
WeddingShare.UnitTests/Tests/Helpers/ConfigHelper.cs
Normal file
165
WeddingShare.UnitTests/Tests/Helpers/ConfigHelper.cs
Normal file
@@ -0,0 +1,165 @@
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using WeddingShare.Helpers;
|
||||
using WeddingShare.UnitTests.Helpers;
|
||||
|
||||
namespace WeddingShare.UnitTests.Tests.Helpers
|
||||
{
|
||||
public class ConfigHelperTests
|
||||
{
|
||||
private readonly IConfiguration _configuration;
|
||||
private readonly IEnvironmentWrapper _environment = Substitute.For<IEnvironmentWrapper>();
|
||||
private readonly ILogger<ConfigHelper> _logger = Substitute.For<ILogger<ConfigHelper>>();
|
||||
|
||||
public ConfigHelperTests()
|
||||
{
|
||||
_environment.GetEnvironmentVariable("VERSION").Returns("v2.0.0");
|
||||
_environment.GetEnvironmentVariable("ENVKEY_1").Returns("EnvValue1");
|
||||
_environment.GetEnvironmentVariable("ENVKEY_2").Returns("EnvValue2");
|
||||
_environment.GetEnvironmentVariable("ENVKEY_3").Returns("EnvValue3");
|
||||
|
||||
_configuration = ConfigurationHelper.MockConfiguration(new Dictionary<string, string?>()
|
||||
{
|
||||
{ "Release:Version", "v1.0.0" },
|
||||
|
||||
{ "String1:Key1", "Value1" },
|
||||
{ "String1:Key2", "Value2" },
|
||||
{ "String2:Key1", "Value3" },
|
||||
|
||||
{ "Int1:Key1", "1" },
|
||||
{ "Int1:Key2", "2" },
|
||||
{ "Int2:Key1", "3" },
|
||||
|
||||
{ "Long1:Key1", "4" },
|
||||
{ "Long1:Key2", "5" },
|
||||
{ "Long2:Key1", "6" },
|
||||
|
||||
{ "Decimal1:Key1", "4.12" },
|
||||
{ "Decimal1:Key2", "5.45" },
|
||||
{ "Decimal2:Key1", "6.733" },
|
||||
|
||||
{ "Double1:Key1", "4.12" },
|
||||
{ "Double1:Key2", "5.45" },
|
||||
{ "Double2:Key1", "6.733" },
|
||||
|
||||
{ "Boolean1:Key1", "true" },
|
||||
{ "Boolean1:Key2", "false" },
|
||||
{ "Boolean2:Key1", "true" },
|
||||
|
||||
{ "DateTime1:Key1", "1987-11-20 08:00:00" },
|
||||
{ "DateTime1:Key2", "2000-08-12 12:00:00" },
|
||||
{ "DateTime2:Key1", "2018-01-01 20:30:10" },
|
||||
});
|
||||
}
|
||||
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
}
|
||||
|
||||
[TestCase("ENVKEY:1", "EnvValue1")]
|
||||
[TestCase("ENVKEY:2", "EnvValue2")]
|
||||
[TestCase("ENVKEY:3", "EnvValue3")]
|
||||
[TestCase("ENVKEY:4", null)]
|
||||
[TestCase("VERSION", "v2.0.0")]
|
||||
public void ConfigHelper_GetEnvironmentVariable(string section, string? expected)
|
||||
{
|
||||
var actual = new ConfigHelper(_environment, _configuration, _logger).GetEnvironmentVariable(section);
|
||||
Assert.That(actual, Is.EqualTo(expected));
|
||||
}
|
||||
|
||||
[TestCase("String1", "Key1", "Value1")]
|
||||
[TestCase("String1", "Key2", "Value2")]
|
||||
[TestCase("String2", "Key1", "Value3")]
|
||||
[TestCase("String2", "Key2", null)]
|
||||
[TestCase("Release", "Version", "v1.0.0")]
|
||||
public void ConfigHelper_GetConfigValue(string section, string key, string? expected)
|
||||
{
|
||||
var actual = new ConfigHelper(_environment, _configuration, _logger).GetConfigValue(section, key);
|
||||
Assert.That(actual, Is.EqualTo(expected));
|
||||
}
|
||||
|
||||
[TestCase("String1", "Key1", "Value1")]
|
||||
[TestCase("String1", "Key2", "Value2")]
|
||||
[TestCase("String2", "Key1", "Value3")]
|
||||
[TestCase("String2", "Key2", null)]
|
||||
[TestCase("Release", "Version", "v1.0.0")]
|
||||
public void ConfigHelper_Get(string section, string key, string? expected)
|
||||
{
|
||||
var actual = new ConfigHelper(_environment, _configuration, _logger).Get(section, key);
|
||||
Assert.That(actual, Is.EqualTo(expected));
|
||||
}
|
||||
|
||||
[TestCase("String1", "Key1", "Default", "Value1")]
|
||||
[TestCase("String1", "Key2", "Default", "Value2")]
|
||||
[TestCase("String2", "Key1", "Default", "Value3")]
|
||||
[TestCase("String2", "Key2", "Default", "Default")]
|
||||
[TestCase("Release", "Version", "v0.0.0", "v1.0.0")]
|
||||
public void ConfigHelper_GetOrDefault(string section, string key, string defaultValue, string expected)
|
||||
{
|
||||
var actual = new ConfigHelper(_environment, _configuration, _logger).GetOrDefault(section, key, defaultValue);
|
||||
Assert.That(actual, Is.EqualTo(expected));
|
||||
}
|
||||
|
||||
[TestCase("Int1", "Key1", 999, 1)]
|
||||
[TestCase("Int1", "Key2", 999, 2)]
|
||||
[TestCase("Int2", "Key1", 999, 3)]
|
||||
[TestCase("Int2", "Key2", 999, 999)]
|
||||
public void ConfigHelper_GetOrDefault(string section, string key, int defaultValue, int expected)
|
||||
{
|
||||
var actual = new ConfigHelper(_environment, _configuration, _logger).GetOrDefault(section, key, defaultValue);
|
||||
Assert.That(actual, Is.EqualTo(expected));
|
||||
}
|
||||
|
||||
[TestCase("Long1", "Key1", 999, 4)]
|
||||
[TestCase("Long1", "Key2", 999, 5)]
|
||||
[TestCase("Long2", "Key1", 999, 6)]
|
||||
[TestCase("Long2", "Key2", 999, 999)]
|
||||
public void ConfigHelper_GetOrDefault(string section, string key, long defaultValue, long expected)
|
||||
{
|
||||
var actual = new ConfigHelper(_environment, _configuration, _logger).GetOrDefault(section, key, defaultValue);
|
||||
Assert.That(actual, Is.EqualTo(expected));
|
||||
}
|
||||
|
||||
[TestCase("Decimal1", "Key1", 999, 4.12)]
|
||||
[TestCase("Decimal1", "Key2", 999, 5.45)]
|
||||
[TestCase("Decimal2", "Key1", 999, 6.733)]
|
||||
[TestCase("Decimal2", "Key2", 999, 999)]
|
||||
public void ConfigHelper_GetOrDefault(string section, string key, decimal defaultValue, decimal expected)
|
||||
{
|
||||
var actual = new ConfigHelper(_environment, _configuration, _logger).GetOrDefault(section, key, defaultValue);
|
||||
Assert.That(actual, Is.EqualTo(expected));
|
||||
}
|
||||
|
||||
[TestCase("Double1", "Key1", 999, 4.12)]
|
||||
[TestCase("Double1", "Key2", 999, 5.45)]
|
||||
[TestCase("Double2", "Key1", 999, 6.733)]
|
||||
[TestCase("Double2", "Key2", 999, 999)]
|
||||
public void ConfigHelper_GetOrDefault(string section, string key, double defaultValue, double expected)
|
||||
{
|
||||
var actual = new ConfigHelper(_environment, _configuration, _logger).GetOrDefault(section, key, defaultValue);
|
||||
Assert.That(actual, Is.EqualTo(expected));
|
||||
}
|
||||
|
||||
[TestCase("Boolean1", "Key1", false, true)]
|
||||
[TestCase("Boolean1", "Key2", false, false)]
|
||||
[TestCase("Boolean2", "Key1", false, true)]
|
||||
[TestCase("Boolean2", "Key2", true, true)]
|
||||
public void ConfigHelper_GetOrDefault(string section, string key, bool defaultValue, bool expected)
|
||||
{
|
||||
var actual = new ConfigHelper(_environment, _configuration, _logger).GetOrDefault(section, key, defaultValue);
|
||||
Assert.That(actual, Is.EqualTo(expected));
|
||||
}
|
||||
|
||||
[TestCase("DateTime1", "Key1", null, "1987-11-20 08:00:00")]
|
||||
[TestCase("DateTime1", "Key2", null, "2000-08-12 12:00:00")]
|
||||
[TestCase("DateTime2", "Key1", null, "2018-01-01 20:30:10")]
|
||||
[TestCase("DateTime2", "Key2", null, null)]
|
||||
[TestCase("DateTime3", "Key3", "2350-05-05 00:05:12", "2350-05-05 00:05:12")]
|
||||
public void ConfigHelper_GetOrDefault(string section, string key, DateTime? defaultValue, string? expected)
|
||||
{
|
||||
var actual = new ConfigHelper(_environment, _configuration, _logger).GetOrDefault(section, key, defaultValue);
|
||||
Assert.That(actual, Is.EqualTo(!string.IsNullOrWhiteSpace(expected) ? DateTime.Parse(expected) : null));
|
||||
}
|
||||
}
|
||||
}
|
||||
41
WeddingShare.UnitTests/Tests/Helpers/ImageHelper.cs
Normal file
41
WeddingShare.UnitTests/Tests/Helpers/ImageHelper.cs
Normal file
@@ -0,0 +1,41 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
using SixLabors.ImageSharp;
|
||||
using SixLabors.ImageSharp.PixelFormats;
|
||||
using WeddingShare.Enums;
|
||||
using WeddingShare.Helpers;
|
||||
|
||||
namespace WeddingShare.UnitTests.Tests.Helpers
|
||||
{
|
||||
public class ImageHelperTests
|
||||
{
|
||||
private readonly ILogger<ImageHelper> _logger = Substitute.For<ILogger<ImageHelper>>();
|
||||
private readonly IDictionary<ImageOrientation, Image?> _imageCollection;
|
||||
|
||||
public ImageHelperTests()
|
||||
{
|
||||
_imageCollection = new Dictionary<ImageOrientation, Image?>()
|
||||
{
|
||||
{ ImageOrientation.Square, new Image<Rgba32>(100, 100) },
|
||||
{ ImageOrientation.Landscape, new Image<Rgba32>(200, 100) },
|
||||
{ ImageOrientation.Portrait, new Image<Rgba32>(100, 200) }
|
||||
};
|
||||
}
|
||||
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
}
|
||||
|
||||
[TestCase(ImageOrientation.Square)]
|
||||
[TestCase(ImageOrientation.Landscape)]
|
||||
[TestCase(ImageOrientation.Portrait)]
|
||||
public void ImageHelper_GetOrientation(ImageOrientation orientation)
|
||||
{
|
||||
var image = _imageCollection[orientation];
|
||||
Assert.IsNotNull(image);
|
||||
|
||||
var actual = new ImageHelper(_logger).GetOrientation(image);
|
||||
Assert.That(actual, Is.EqualTo(orientation));
|
||||
}
|
||||
}
|
||||
}
|
||||
75
WeddingShare.UnitTests/Tests/Helpers/SecretKeyHelper.cs
Normal file
75
WeddingShare.UnitTests/Tests/Helpers/SecretKeyHelper.cs
Normal file
@@ -0,0 +1,75 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
using WeddingShare.Helpers;
|
||||
using WeddingShare.Helpers.Database;
|
||||
using WeddingShare.Models.Database;
|
||||
using WeddingShare.UnitTests.Helpers;
|
||||
|
||||
namespace WeddingShare.UnitTests.Tests.Helpers
|
||||
{
|
||||
public class SecretKeyHelperTests
|
||||
{
|
||||
private readonly IDatabaseHelper _database = Substitute.For<IDatabaseHelper>();
|
||||
|
||||
public SecretKeyHelperTests()
|
||||
{
|
||||
_database.GetGallery("Gallery1").Returns(new GalleryModel() { SecretKey = "001" });
|
||||
_database.GetGallery("Gallery2").Returns(new GalleryModel() { SecretKey = "002" });
|
||||
}
|
||||
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
}
|
||||
|
||||
[TestCase()]
|
||||
public async Task SecretKeyHelper_GetGallerySecretKey_DefaultEnvKey()
|
||||
{
|
||||
var environment = Substitute.For<IEnvironmentWrapper>();
|
||||
environment.GetEnvironmentVariable("SECRET_KEY").Returns("123");
|
||||
|
||||
var configuration = ConfigurationHelper.MockConfiguration(new Dictionary<string, string?>()
|
||||
{
|
||||
{ "Secret_Key_Gallery2", "002" }
|
||||
});
|
||||
|
||||
var config = new ConfigHelper(environment, configuration, Substitute.For<ILogger<ConfigHelper>>());
|
||||
|
||||
var actual = await new SecretKeyHelper(config, _database).GetGallerySecretKey("Gallery3");
|
||||
Assert.That(actual, Is.EqualTo("123"));
|
||||
}
|
||||
|
||||
[TestCase()]
|
||||
public async Task SecretKeyHelper_GetGallerySecretKey_GalleryEnvKey()
|
||||
{
|
||||
var environment = Substitute.For<IEnvironmentWrapper>();
|
||||
environment.GetEnvironmentVariable("SECRET_KEY").Returns("123");
|
||||
environment.GetEnvironmentVariable("SECRET_KEY_GALLERY1").Returns("001");
|
||||
|
||||
var configuration = ConfigurationHelper.MockConfiguration(new Dictionary<string, string?>()
|
||||
{
|
||||
{ "Secret_Key_Gallery2", "002" }
|
||||
});
|
||||
|
||||
var config = new ConfigHelper(environment, configuration, Substitute.For<ILogger<ConfigHelper>>());
|
||||
|
||||
var actual = await new SecretKeyHelper(config, _database).GetGallerySecretKey("Gallery1");
|
||||
Assert.That(actual, Is.EqualTo("001"));
|
||||
}
|
||||
|
||||
[TestCase("Gallery1", "001")]
|
||||
[TestCase("Gallery2", "002")]
|
||||
[TestCase("Gallery3", null)]
|
||||
public async Task SecretKeyHelper_GetGallerySecretKey_Database(string galleryId, string key)
|
||||
{
|
||||
var environment = Substitute.For<IEnvironmentWrapper>();
|
||||
environment.GetEnvironmentVariable(Arg.Any<string>()).Returns(string.Empty);
|
||||
|
||||
var configuration = ConfigurationHelper.MockConfiguration(new Dictionary<string, string?>());
|
||||
|
||||
var config = new ConfigHelper(environment, configuration, Substitute.For<ILogger<ConfigHelper>>());
|
||||
|
||||
var actual = await new SecretKeyHelper(config, _database).GetGallerySecretKey(galleryId);
|
||||
Assert.That(actual, Is.EqualTo(key));
|
||||
}
|
||||
}
|
||||
}
|
||||
26
WeddingShare.UnitTests/WeddingShare.UnitTests.csproj
Normal file
26
WeddingShare.UnitTests/WeddingShare.UnitTests.csproj
Normal file
@@ -0,0 +1,26 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
|
||||
<IsPackable>false</IsPackable>
|
||||
<IsTestProject>true</IsTestProject>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.6.0" />
|
||||
<PackageReference Include="NSubstitute" Version="5.3.0" />
|
||||
<PackageReference Include="NUnit" Version="3.13.3" />
|
||||
<PackageReference Include="NUnit3TestAdapter" Version="4.2.1" />
|
||||
<PackageReference Include="NUnit.Analyzers" Version="3.6.1" />
|
||||
<PackageReference Include="coverlet.collector" Version="6.0.0" />
|
||||
<PackageReference Include="SixLabors.ImageSharp" Version="3.1.6" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\WeddingShare\WeddingShare.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
@@ -5,6 +5,8 @@ VisualStudioVersion = 17.8.34511.84
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WeddingShare", "WeddingShare\WeddingShare.csproj", "{1E5B4227-C87D-42DA-9946-4F86C9034F35}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WeddingShare.UnitTests", "WeddingShare.UnitTests\WeddingShare.UnitTests.csproj", "{B1BAAF2F-454D-4B57-AD6B-9701D73EB8C6}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
@@ -15,6 +17,10 @@ Global
|
||||
{1E5B4227-C87D-42DA-9946-4F86C9034F35}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{1E5B4227-C87D-42DA-9946-4F86C9034F35}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{1E5B4227-C87D-42DA-9946-4F86C9034F35}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{B1BAAF2F-454D-4B57-AD6B-9701D73EB8C6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{B1BAAF2F-454D-4B57-AD6B-9701D73EB8C6}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{B1BAAF2F-454D-4B57-AD6B-9701D73EB8C6}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{B1BAAF2F-454D-4B57-AD6B-9701D73EB8C6}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
||||
52
WeddingShare/Attributes/AllowGuestCreateAttribute.cs
Normal file
52
WeddingShare/Attributes/AllowGuestCreateAttribute.cs
Normal file
@@ -0,0 +1,52 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Mvc.Filters;
|
||||
using WeddingShare.Helpers;
|
||||
using WeddingShare.Helpers.Database;
|
||||
|
||||
namespace WeddingShare.Attributes
|
||||
{
|
||||
public class AllowGuestCreateAttribute : ActionFilterAttribute
|
||||
{
|
||||
public override void OnActionExecuting(ActionExecutingContext filterContext)
|
||||
{
|
||||
try
|
||||
{
|
||||
var request = filterContext.HttpContext.Request;
|
||||
|
||||
var galleryId = (request.Query.ContainsKey("id") && !string.IsNullOrWhiteSpace(request.Query["id"])) ? request.Query["id"].ToString().ToLower() : "default";
|
||||
|
||||
if (!string.Equals("default", galleryId, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
var user = filterContext?.HttpContext?.User;
|
||||
if (user?.Identity == null || !user.Identity.IsAuthenticated)
|
||||
{
|
||||
var configHelper = filterContext.HttpContext.RequestServices.GetService<IConfigHelper>();
|
||||
if (configHelper != null)
|
||||
{
|
||||
if (configHelper.GetOrDefault("Settings", "Disable_Guest_Gallery_Creation", true))
|
||||
{
|
||||
var databaseHelper = filterContext.HttpContext.RequestServices.GetService<IDatabaseHelper>();
|
||||
if (databaseHelper != null)
|
||||
{
|
||||
var gallery = databaseHelper.GetGallery(galleryId).Result;
|
||||
if (gallery == null)
|
||||
{
|
||||
filterContext.Result = new RedirectToActionResult("Index", "Error", new { Reason = ErrorCode.GalleryCreationNotAllowed }, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
var logger = filterContext.HttpContext.RequestServices.GetService<ILogger<RequiresSecretKeyAttribute>>();
|
||||
if (logger != null)
|
||||
{
|
||||
logger.LogError(ex, $"Failed to check guest creation - {ex?.Message}");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
44
WeddingShare/Attributes/RequiresSecretKeyAttribute.cs
Normal file
44
WeddingShare/Attributes/RequiresSecretKeyAttribute.cs
Normal file
@@ -0,0 +1,44 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Mvc.Filters;
|
||||
using WeddingShare.Helpers;
|
||||
|
||||
namespace WeddingShare.Attributes
|
||||
{
|
||||
public class RequiresSecretKeyAttribute : ActionFilterAttribute
|
||||
{
|
||||
public override void OnActionExecuting(ActionExecutingContext filterContext)
|
||||
{
|
||||
try
|
||||
{
|
||||
var request = filterContext.HttpContext.Request;
|
||||
|
||||
var secretKeyHelper = filterContext.HttpContext.RequestServices.GetService<ISecretKeyHelper>();
|
||||
if (secretKeyHelper != null)
|
||||
{
|
||||
var galleryId = (request.Query.ContainsKey("id") && !string.IsNullOrWhiteSpace(request.Query["id"])) ? request.Query["id"].ToString().ToLower() : "default";
|
||||
var secretKey = secretKeyHelper.GetGallerySecretKey(galleryId).Result;
|
||||
|
||||
var key = request.Query.ContainsKey("key") ? request.Query["key"].ToString() : string.Empty;
|
||||
if (!string.IsNullOrWhiteSpace(secretKey) && !string.Equals(secretKey, key))
|
||||
{
|
||||
var logger = filterContext.HttpContext.RequestServices.GetService<ILogger<RequiresSecretKeyAttribute>>();
|
||||
if (logger != null)
|
||||
{
|
||||
logger.LogWarning($"A request was made to an endpoint with an invalid secure key");
|
||||
}
|
||||
|
||||
filterContext.Result = new RedirectToActionResult("Index", "Error", new { Reason = ErrorCode.InvalidSecretKey }, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
var logger = filterContext.HttpContext.RequestServices.GetService<ILogger<RequiresSecretKeyAttribute>>();
|
||||
if (logger != null)
|
||||
{
|
||||
logger.LogError(ex, $"Failed to validate secure key - {ex?.Message}");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -8,6 +8,10 @@ using WeddingShare.Enums;
|
||||
using WeddingShare.Helpers;
|
||||
using WeddingShare.Views.Admin;
|
||||
using WeddingShare.Models;
|
||||
using WeddingShare.Helpers.Database;
|
||||
using WeddingShare.Models.Database;
|
||||
using System.IO;
|
||||
using System.IO.Compression;
|
||||
|
||||
namespace WeddingShare.Controllers
|
||||
{
|
||||
@@ -16,19 +20,25 @@ namespace WeddingShare.Controllers
|
||||
{
|
||||
private readonly IWebHostEnvironment _hostingEnvironment;
|
||||
private readonly IConfigHelper _config;
|
||||
private readonly IDatabaseHelper _database;
|
||||
private readonly IImageHelper _imageHelper;
|
||||
private readonly ILogger _logger;
|
||||
private readonly IStringLocalizer<AdminController> _localizer;
|
||||
|
||||
private readonly string UploadsDirectory;
|
||||
private readonly string ThumbnailsDirectory;
|
||||
|
||||
public AdminController(IWebHostEnvironment hostingEnvironment, IConfigHelper config, ILogger<AdminController> logger, IStringLocalizer<AdminController> localizer)
|
||||
public AdminController(IWebHostEnvironment hostingEnvironment, IConfigHelper config, IDatabaseHelper database, IImageHelper imageHelper, ILogger<AdminController> logger, IStringLocalizer<AdminController> localizer)
|
||||
{
|
||||
_hostingEnvironment = hostingEnvironment;
|
||||
_config = config;
|
||||
_database = database;
|
||||
_imageHelper = imageHelper;
|
||||
_logger = logger;
|
||||
_localizer = localizer;
|
||||
|
||||
UploadsDirectory = Path.Combine(_hostingEnvironment.WebRootPath, "uploads");
|
||||
ThumbnailsDirectory = Path.Combine(_hostingEnvironment.WebRootPath, "thumbnails");
|
||||
}
|
||||
|
||||
[AllowAnonymous]
|
||||
@@ -38,7 +48,7 @@ namespace WeddingShare.Controllers
|
||||
try
|
||||
{
|
||||
var passkey = _config.Get("Settings", "Admin_Password");
|
||||
if (string.IsNullOrEmpty(passkey) || string.Equals(passkey, model?.Password))
|
||||
if (string.IsNullOrWhiteSpace(passkey) || string.Equals(passkey, model?.Password))
|
||||
{
|
||||
var claims = new List<Claim>
|
||||
{
|
||||
@@ -57,7 +67,7 @@ namespace WeddingShare.Controllers
|
||||
_logger.LogError(ex, $"{_localizer["Login_Failed"].Value} - {ex?.Message}");
|
||||
}
|
||||
|
||||
return Json(new { success = false, message = "Invalid password" });
|
||||
return Json(new { success = false });
|
||||
}
|
||||
|
||||
[Authorize]
|
||||
@@ -69,7 +79,7 @@ namespace WeddingShare.Controllers
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public IActionResult Index()
|
||||
public async Task<IActionResult> Index()
|
||||
{
|
||||
if (User?.Identity == null || !User.Identity.IsAuthenticated)
|
||||
{
|
||||
@@ -80,10 +90,19 @@ namespace WeddingShare.Controllers
|
||||
|
||||
try
|
||||
{
|
||||
if (Directory.Exists(UploadsDirectory))
|
||||
if (!_config.GetOrDefault("Settings", "Single_Gallery_Mode", false))
|
||||
{
|
||||
model.Galleries = Directory.GetDirectories(UploadsDirectory)?.Select(x => new KeyValuePair<string, string>(Path.GetFileName(x), x))?.ToList();
|
||||
model.PendingRequests = model.Galleries?.SelectMany(x => Directory.GetFiles(Path.Combine(x.Value, "Pending"), "*.*", SearchOption.TopDirectoryOnly))?.Select(x => x.Replace(UploadsDirectory, string.Empty))?.ToList();
|
||||
model.Galleries = await _database.GetAllGalleries();
|
||||
model.PendingRequests = await _database.GetPendingGalleryItems();
|
||||
}
|
||||
else
|
||||
{
|
||||
var gallery = await _database.GetGallery("default");
|
||||
if (gallery != null)
|
||||
{
|
||||
model.Galleries = new List<GalleryModel>() { gallery };
|
||||
model.PendingRequests = await _database.GetPendingGalleryItems(gallery.Id);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
@@ -95,23 +114,42 @@ namespace WeddingShare.Controllers
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public IActionResult ReviewPhoto(string galleryId, string photoId, ReviewAction action)
|
||||
public async Task<IActionResult> ReviewPhoto(int id, ReviewAction action)
|
||||
{
|
||||
if (User?.Identity != null && User.Identity.IsAuthenticated)
|
||||
{
|
||||
try
|
||||
{
|
||||
var galleryDir = Path.Combine(UploadsDirectory, galleryId);
|
||||
var reviewFile = Path.Combine(galleryDir, "Pending", photoId);
|
||||
if (System.IO.File.Exists(reviewFile))
|
||||
{
|
||||
var review = await _database.GetPendingGalleryItem(id);
|
||||
if (review != null)
|
||||
{
|
||||
var galleryDir = Path.Combine(UploadsDirectory, review.GalleryName);
|
||||
var reviewFile = Path.Combine(galleryDir, "Pending", review.Title);
|
||||
if (action == ReviewAction.APPROVED)
|
||||
{
|
||||
System.IO.File.Move(reviewFile, Path.Combine(galleryDir, Path.GetFileName(reviewFile)));
|
||||
if (!Directory.Exists(ThumbnailsDirectory))
|
||||
{
|
||||
Directory.CreateDirectory(ThumbnailsDirectory);
|
||||
}
|
||||
|
||||
await _imageHelper.GenerateThumbnail(reviewFile, Path.Combine(ThumbnailsDirectory, $"{Path.GetFileNameWithoutExtension(reviewFile)}.webp"), _config.GetOrDefault("Settings", "Thumbnail_Size", 720));
|
||||
|
||||
if (System.IO.File.Exists(reviewFile))
|
||||
{
|
||||
System.IO.File.Move(reviewFile, Path.Combine(galleryDir, review.Title));
|
||||
}
|
||||
|
||||
review.State = GalleryItemState.Approved;
|
||||
await _database.EditGalleryItem(review);
|
||||
}
|
||||
else if (action == ReviewAction.REJECTED)
|
||||
{
|
||||
System.IO.File.Delete(reviewFile);
|
||||
if (System.IO.File.Exists(reviewFile))
|
||||
{
|
||||
System.IO.File.Delete(reviewFile);
|
||||
}
|
||||
|
||||
await _database.DeleteGalleryItem(review);
|
||||
}
|
||||
else if (action == ReviewAction.UNKNOWN)
|
||||
{
|
||||
@@ -133,5 +171,156 @@ namespace WeddingShare.Controllers
|
||||
|
||||
return Json(new { success = false });
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public async Task<IActionResult> AddGallery(GalleryModel model)
|
||||
{
|
||||
if (User?.Identity != null && User.Identity.IsAuthenticated)
|
||||
{
|
||||
if (!string.IsNullOrWhiteSpace(model?.Name))
|
||||
{
|
||||
try
|
||||
{
|
||||
var check = await _database.GetGallery(model.Name);
|
||||
if (check == null)
|
||||
{
|
||||
return Json(new { success = string.Equals(model?.Name, (await _database.AddGallery(model))?.Name, StringComparison.OrdinalIgnoreCase) });
|
||||
}
|
||||
else
|
||||
{
|
||||
return Json(new { success = false, message = _localizer["Gallery_Name_Already_Exists"].Value });
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, $"{_localizer["Failed_Add_Gallery"].Value} - {ex?.Message}");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return Json(new { success = false, message = _localizer["Name_Cannot_Be_Blank"].Value });
|
||||
}
|
||||
}
|
||||
|
||||
return Json(new { success = false });
|
||||
}
|
||||
|
||||
[HttpPut]
|
||||
public async Task<IActionResult> EditGallery(GalleryModel model)
|
||||
{
|
||||
if (User?.Identity != null && User.Identity.IsAuthenticated)
|
||||
{
|
||||
if (!string.IsNullOrWhiteSpace(model?.Name))
|
||||
{
|
||||
try
|
||||
{
|
||||
var check = await _database.GetGallery(model.Name);
|
||||
if (check == null || model.Id == check.Id)
|
||||
{
|
||||
var gallery = await _database.GetGallery(model.Id);
|
||||
if (gallery != null)
|
||||
{
|
||||
gallery.Name = model.Name;
|
||||
gallery.SecretKey = model.SecretKey;
|
||||
|
||||
return Json(new { success = string.Equals(model?.Name, (await _database.EditGallery(gallery))?.Name, StringComparison.OrdinalIgnoreCase) });
|
||||
}
|
||||
else
|
||||
{
|
||||
return Json(new { success = false, message = _localizer["Failed_Edit_Gallery"].Value });
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return Json(new { success = false, message = _localizer["Gallery_Name_Already_Exists"].Value });
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, $"{_localizer["Failed_Edit_Gallery"].Value} - {ex?.Message}");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return Json(new { success = false, message = _localizer["Name_Cannot_Be_Blank"].Value });
|
||||
}
|
||||
}
|
||||
|
||||
return Json(new { success = false });
|
||||
}
|
||||
|
||||
[HttpDelete]
|
||||
public async Task<IActionResult> DeleteGallery(int id)
|
||||
{
|
||||
if (User?.Identity != null && User.Identity.IsAuthenticated)
|
||||
{
|
||||
try
|
||||
{
|
||||
var gallery = await _database.GetGallery(id);
|
||||
if (gallery != null)
|
||||
{
|
||||
var galleryDir = Path.Combine(UploadsDirectory, gallery.Name);
|
||||
if (Directory.Exists(galleryDir))
|
||||
{
|
||||
Directory.Delete(galleryDir, true);
|
||||
}
|
||||
|
||||
return Json(new { success = await _database.DeleteGallery(gallery) });
|
||||
}
|
||||
else
|
||||
{
|
||||
return Json(new { success = false, message = _localizer["Failed_Delete_Gallery"].Value });
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, $"{_localizer["Failed_Delete_Gallery"].Value} - {ex?.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
return Json(new { success = false });
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public async Task<IActionResult> DownloadGallery(int id)
|
||||
{
|
||||
if (User?.Identity != null && User.Identity.IsAuthenticated)
|
||||
{
|
||||
try
|
||||
{
|
||||
var gallery = await _database.GetGallery(id);
|
||||
if (gallery != null)
|
||||
{
|
||||
var galleryDir = Path.Combine(UploadsDirectory, gallery.Name);
|
||||
if (Directory.Exists(galleryDir))
|
||||
{
|
||||
var tempZipDir = $"Temp";
|
||||
if (!Directory.Exists(tempZipDir))
|
||||
{
|
||||
Directory.CreateDirectory(tempZipDir);
|
||||
}
|
||||
|
||||
var tempZipFile = Path.Combine(tempZipDir, $"{gallery.Name}-{DateTime.Now.ToString("yyyy-MM-dd_HH-mm-ss")}.zip");
|
||||
ZipFile.CreateFromDirectory(galleryDir, tempZipFile, CompressionLevel.Optimal, false);
|
||||
|
||||
byte[] bytes = System.IO.File.ReadAllBytes(tempZipFile);
|
||||
System.IO.File.Delete(tempZipFile);
|
||||
|
||||
return Json(new { success = true, filename = Path.GetFileName(tempZipFile), content = Convert.ToBase64String(bytes, 0, bytes.Length) });
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return Json(new { success = false, message = _localizer["Failed_Download_Gallery"].Value });
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, $"{_localizer["Failed_Download_Gallery"].Value} - {ex?.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
return Json(new { success = false });
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,30 +1,19 @@
|
||||
using System.Diagnostics;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using WeddingShare.Models;
|
||||
|
||||
namespace WeddingShare.Controllers
|
||||
{
|
||||
[AllowAnonymous]
|
||||
public class ErrorController : Controller
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
|
||||
public ErrorController(ILogger<ErrorController> logger)
|
||||
public ErrorController()
|
||||
{
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
|
||||
public IActionResult Index()
|
||||
{
|
||||
return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
|
||||
}
|
||||
|
||||
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
|
||||
public IActionResult AccessDenied()
|
||||
{
|
||||
return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
|
||||
return View();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,10 +1,14 @@
|
||||
using System.Diagnostics;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Extensions.Caching.Memory;
|
||||
using Microsoft.Extensions.Localization;
|
||||
using WeddingShare.Attributes;
|
||||
using WeddingShare.Enums;
|
||||
using WeddingShare.Extensions;
|
||||
using WeddingShare.Helpers;
|
||||
using WeddingShare.Helpers.Database;
|
||||
using WeddingShare.Models;
|
||||
using WeddingShare.Models.Database;
|
||||
|
||||
namespace WeddingShare.Controllers
|
||||
{
|
||||
@@ -13,62 +17,97 @@ namespace WeddingShare.Controllers
|
||||
{
|
||||
private readonly IWebHostEnvironment _hostingEnvironment;
|
||||
private readonly IConfigHelper _config;
|
||||
private readonly IDatabaseHelper _database;
|
||||
private readonly ISecretKeyHelper _secretKey;
|
||||
private readonly IMemoryCache _memoryCache;
|
||||
private readonly ILogger _logger;
|
||||
private readonly IStringLocalizer<GalleryController> _localizer;
|
||||
|
||||
private readonly string UploadsDirectory;
|
||||
private readonly string ThumbnailsDirectory;
|
||||
|
||||
public GalleryController(IWebHostEnvironment hostingEnvironment, IConfigHelper config, ILogger<GalleryController> logger, IStringLocalizer<GalleryController> localizer)
|
||||
public GalleryController(IWebHostEnvironment hostingEnvironment, IConfigHelper config, IDatabaseHelper database, ISecretKeyHelper secretKey, IMemoryCache cache, ILogger<GalleryController> logger, IStringLocalizer<GalleryController> localizer)
|
||||
{
|
||||
_hostingEnvironment = hostingEnvironment;
|
||||
_config = config;
|
||||
_database = database;
|
||||
_secretKey = secretKey;
|
||||
_memoryCache = cache;
|
||||
_logger = logger;
|
||||
_localizer = localizer;
|
||||
|
||||
UploadsDirectory = Path.Combine(_hostingEnvironment.WebRootPath, "uploads");
|
||||
ThumbnailsDirectory = Path.Combine(_hostingEnvironment.WebRootPath, "thumbnails");
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public IActionResult Index(string id, string? key)
|
||||
[RequiresSecretKey]
|
||||
[AllowGuestCreate]
|
||||
public async Task<IActionResult> Index(string id = "default", string? key = null)
|
||||
{
|
||||
if (_config.GetOrDefault("Settings", "Single_Gallery_Mode", false))
|
||||
id = id.ToLower();
|
||||
if (string.IsNullOrWhiteSpace(id) || _config.GetOrDefault("Settings", "Single_Gallery_Mode", false))
|
||||
{
|
||||
id = "default";
|
||||
}
|
||||
|
||||
id = id.ToLower();
|
||||
|
||||
var secretKey = _config.Get("Settings", "Secret_Key");
|
||||
if (!string.IsNullOrEmpty(secretKey) && !string.Equals(secretKey, key))
|
||||
try
|
||||
{
|
||||
_logger.LogWarning(_localizer["Invalid_Security_Key_Warning"].Value);
|
||||
ViewBag.ErrorMessage = _localizer["Invalid_Gallery_Key"].Value;
|
||||
var userAgent = Request.Headers["User-Agent"].ToString();
|
||||
if (!_memoryCache.TryGetValue<bool>(userAgent, out var isMobile))
|
||||
{
|
||||
var dd = new DeviceDetectorNET.DeviceDetector(userAgent);
|
||||
dd.Parse();
|
||||
|
||||
return View("~/Views/Home/Index.cshtml");
|
||||
isMobile = dd.IsParsed() && dd.IsMobile();
|
||||
|
||||
_memoryCache.Set(userAgent, isMobile);
|
||||
}
|
||||
|
||||
ViewBag.IsMobile = isMobile;
|
||||
}
|
||||
else if (string.IsNullOrEmpty(id))
|
||||
{
|
||||
ViewBag.ErrorMessage = _localizer["Invalid_Gallery_Id"].Value;
|
||||
|
||||
return View("~/Views/Home/Index.cshtml");
|
||||
catch
|
||||
{
|
||||
ViewBag.IsMobile = false;
|
||||
}
|
||||
|
||||
ViewBag.SecretKey = key;
|
||||
|
||||
var galleryPath = Path.Combine(UploadsDirectory, id);
|
||||
var allowedFileTypes = _config.GetOrDefault("Settings", "Allowed_File_Types", ".jpg,.jpeg,.png").Split(',', StringSplitOptions.TrimEntries | StringSplitOptions.RemoveEmptyEntries);
|
||||
var files = Directory.Exists(galleryPath) ? Directory.GetFiles(galleryPath, "*.*", SearchOption.TopDirectoryOnly)?.Where(x => allowedFileTypes.Any(y => string.Equals(Path.GetExtension(x).Trim('.'), y.Trim('.'), StringComparison.OrdinalIgnoreCase))) : null;
|
||||
var pendingPath = Path.Combine(galleryPath, "Pending");
|
||||
var images = new PhotoGallery(_config.GetOrDefault("Settings", "Gallery_Columns", 4))
|
||||
if (!Directory.Exists(galleryPath))
|
||||
{
|
||||
GalleryId = id,
|
||||
GalleryPath = $"/{galleryPath.Remove(_hostingEnvironment.WebRootPath).Replace('\\', '/').TrimStart('/')}",
|
||||
Images = files?.OrderByDescending(x => new FileInfo(x).CreationTimeUtc)?.Select(x => Path.GetFileName(x))?.ToList(),
|
||||
PendingCount = Directory.Exists(pendingPath) ? Directory.GetFiles(pendingPath, "*.*", SearchOption.TopDirectoryOnly).Length : 0,
|
||||
FileUploader = !_config.GetOrDefault("Settings", "Disable_Upload", false) ? new FileUploader(id, "/Gallery/UploadImage") : null
|
||||
};
|
||||
Directory.CreateDirectory(galleryPath);
|
||||
Directory.CreateDirectory(Path.Combine(galleryPath, "Pending"));
|
||||
}
|
||||
|
||||
GalleryModel? gallery = await _database.GetGallery(id);
|
||||
if (gallery == null)
|
||||
{
|
||||
gallery = await _database.AddGallery(new GalleryModel()
|
||||
{
|
||||
Name = id.ToLower(),
|
||||
SecretKey = key
|
||||
});
|
||||
}
|
||||
|
||||
if (gallery != null)
|
||||
{
|
||||
var allowedFileTypes = _config.GetOrDefault("Settings", "Allowed_File_Types", ".jpg,.jpeg,.png").Split(',', StringSplitOptions.TrimEntries | StringSplitOptions.RemoveEmptyEntries);
|
||||
var images = new PhotoGallery(_config.GetOrDefault("Settings", "Gallery_Columns", 4))
|
||||
{
|
||||
GalleryId = id,
|
||||
GalleryPath = $"/{galleryPath.Remove(_hostingEnvironment.WebRootPath).Replace('\\', '/').TrimStart('/')}",
|
||||
ThumbnailsPath = $"/{ThumbnailsDirectory.Remove(_hostingEnvironment.WebRootPath).Replace('\\', '/').TrimStart('/')}",
|
||||
Images = (await _database.GetAllGalleryItems(gallery.Id, GalleryItemState.Approved))?.Where(x => allowedFileTypes.Any(y => string.Equals(Path.GetExtension(x.Title).Trim('.'), y.Trim('.'), StringComparison.OrdinalIgnoreCase)))?.Select(x => Path.GetFileName(x.Title))?.ToList(),
|
||||
PendingCount = gallery?.PendingItems ?? 0,
|
||||
FileUploader = !_config.GetOrDefault("Settings", "Disable_Upload", false) || (User?.Identity != null && User.Identity.IsAuthenticated) ? new FileUploader(id, "/Gallery/UploadImage") : null
|
||||
};
|
||||
|
||||
return View(images);
|
||||
}
|
||||
|
||||
return View(new PhotoGallery());
|
||||
|
||||
return View(images);
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
@@ -76,79 +115,87 @@ namespace WeddingShare.Controllers
|
||||
{
|
||||
try
|
||||
{
|
||||
var secretKey = _config.Get("Settings", "Secret_Key");
|
||||
var key = Request?.Form?.FirstOrDefault(x => string.Equals("SecretKey", x.Key, StringComparison.OrdinalIgnoreCase)).Value;
|
||||
if (!string.IsNullOrEmpty(secretKey) && !string.Equals(secretKey, key))
|
||||
{
|
||||
_logger.LogWarning(_localizer["Invalid_Security_Key_Warning"].Value);
|
||||
throw new UnauthorizedAccessException(_localizer["Invalid_Access_Token"].Value);
|
||||
}
|
||||
|
||||
string galleryId = Request?.Form?.FirstOrDefault(x => string.Equals("GalleryId", x.Key, StringComparison.OrdinalIgnoreCase)).Value ?? string.Empty;
|
||||
if (string.IsNullOrEmpty(galleryId))
|
||||
string galleryId = (Request?.Form?.FirstOrDefault(x => string.Equals("Id", x.Key, StringComparison.OrdinalIgnoreCase)).Value)?.ToString()?.ToLower() ?? string.Empty;
|
||||
if (string.IsNullOrWhiteSpace(galleryId))
|
||||
{
|
||||
return Json(new { success = true, uploaded = 0, errors = new List<string>() { _localizer["Invalid_Gallery_Id"].Value } });
|
||||
}
|
||||
|
||||
galleryId = galleryId.ToLower();
|
||||
|
||||
var galleryPath = Path.Combine(UploadsDirectory, galleryId);
|
||||
var files = Request?.Form?.Files;
|
||||
if (files != null && files.Count > 0)
|
||||
var gallery = await _database.GetGallery(galleryId);
|
||||
if (gallery != null)
|
||||
{
|
||||
if (!Directory.Exists(galleryPath))
|
||||
var secretKey = await _secretKey.GetGallerySecretKey(galleryId);
|
||||
string key = (Request?.Form?.FirstOrDefault(x => string.Equals("SecretKey", x.Key, StringComparison.OrdinalIgnoreCase)).Value)?.ToString()?.ToLower() ?? string.Empty;
|
||||
if (!string.IsNullOrWhiteSpace(secretKey) && !string.Equals(secretKey, key))
|
||||
{
|
||||
Directory.CreateDirectory(galleryPath);
|
||||
return Json(new { success = true, uploaded = 0, errors = new List<string>() { _localizer["Invalid_Secret_Key_Warning"].Value } });
|
||||
}
|
||||
|
||||
var requiresReview = _config.GetOrDefault("Settings", "Require_Review", true);
|
||||
if (requiresReview)
|
||||
{
|
||||
galleryPath = Path.Combine(galleryPath, "Pending");
|
||||
if (!Directory.Exists(galleryPath))
|
||||
{
|
||||
Directory.CreateDirectory(galleryPath);
|
||||
}
|
||||
}
|
||||
|
||||
var uploaded = 0;
|
||||
var errors = new List<string>();
|
||||
foreach (IFormFile file in files)
|
||||
var files = Request?.Form?.Files;
|
||||
if (files != null && files.Count > 0)
|
||||
{
|
||||
try
|
||||
{
|
||||
var extension = Path.GetExtension(file.FileName);
|
||||
var maxFilesSize = _config.GetOrDefault("Settings", "Max_File_Size_Mb", 10) * 1000000;
|
||||
var requiresReview = _config.GetOrDefault("Settings", "Require_Review", true);
|
||||
|
||||
var allowedFileTypes = _config.GetOrDefault("Settings", "Allowed_File_Types", ".jpg,.jpeg,.png").Split(',', StringSplitOptions.TrimEntries | StringSplitOptions.RemoveEmptyEntries);
|
||||
if (!allowedFileTypes.Any(x => string.Equals(x.Trim('.'), extension.Trim('.'), StringComparison.OrdinalIgnoreCase)))
|
||||
var uploaded = 0;
|
||||
var errors = new List<string>();
|
||||
foreach (IFormFile file in files)
|
||||
{
|
||||
try
|
||||
{
|
||||
errors.Add($"{_localizer["File_Upload_Failed"].Value} '{Path.GetFileName(file.FileName)}'. {_localizer["Invalid_File_Type"].Value}");
|
||||
}
|
||||
else if (file.Length > maxFilesSize)
|
||||
{
|
||||
errors.Add($"{_localizer["File_Upload_Failed"].Value} '{Path.GetFileName(file.FileName)}'. {_localizer["Max_File_Size"].Value} {maxFilesSize} bytes");
|
||||
}
|
||||
else
|
||||
{
|
||||
var filePath = Path.Combine(galleryPath, $"{Guid.NewGuid()}{Path.GetExtension(file.FileName)}");
|
||||
if (!string.IsNullOrEmpty(filePath))
|
||||
var extension = Path.GetExtension(file.FileName);
|
||||
var maxFilesSize = _config.GetOrDefault("Settings", "Max_File_Size_Mb", 10) * 1000000;
|
||||
|
||||
var allowedFileTypes = _config.GetOrDefault("Settings", "Allowed_File_Types", ".jpg,.jpeg,.png").Split(',', StringSplitOptions.TrimEntries | StringSplitOptions.RemoveEmptyEntries);
|
||||
if (!allowedFileTypes.Any(x => string.Equals(x.Trim('.'), extension.Trim('.'), StringComparison.OrdinalIgnoreCase)))
|
||||
{
|
||||
using (var fs = new FileStream(filePath, FileMode.Create))
|
||||
errors.Add($"{_localizer["File_Upload_Failed"].Value} '{Path.GetFileName(file.FileName)}'. {_localizer["Invalid_File_Type"].Value}");
|
||||
}
|
||||
else if (file.Length > maxFilesSize)
|
||||
{
|
||||
errors.Add($"{_localizer["File_Upload_Failed"].Value} '{Path.GetFileName(file.FileName)}'. {_localizer["Max_File_Size"].Value} {maxFilesSize} bytes");
|
||||
}
|
||||
else
|
||||
{
|
||||
var fileName = $"{Guid.NewGuid()}{Path.GetExtension(file.FileName)}";
|
||||
var galleryPath = requiresReview ? Path.Combine(UploadsDirectory, gallery.Name, "Pending") : Path.Combine(UploadsDirectory, gallery.Name);
|
||||
var filePath = Path.Combine(galleryPath, fileName);
|
||||
if (!string.IsNullOrWhiteSpace(filePath))
|
||||
{
|
||||
await file.CopyToAsync(fs);
|
||||
uploaded++;
|
||||
using (var fs = new FileStream(filePath, FileMode.Create))
|
||||
{
|
||||
await file.CopyToAsync(fs);
|
||||
}
|
||||
|
||||
var item = await _database.AddGalleryItem(new GalleryItemModel()
|
||||
{
|
||||
GalleryId = gallery.Id,
|
||||
Title = fileName,
|
||||
State = requiresReview ? GalleryItemState.Pending : GalleryItemState.Approved
|
||||
});
|
||||
|
||||
if (item?.Id > 0)
|
||||
{
|
||||
uploaded++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogWarning(ex, $"{_localizer["Save_To_Gallery_Failed"].Value} - {ex?.Message}");
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogWarning(ex, $"{_localizer["Save_To_Gallery_Failed"].Value} - {ex?.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
return Json(new { success = true, uploaded, requiresReview, errors });
|
||||
return Json(new { success = true, uploaded, requiresReview, errors });
|
||||
}
|
||||
else
|
||||
{
|
||||
return Json(new { success = false, uploaded = 0, errors = new List<string>() { _localizer["No_Files_For_Upload"].Value } });
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return Json(new { success = false, uploaded = 0, errors = new List<string>() { _localizer["Gallery_Does_Not_Exist"].Value } });
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
||||
8
WeddingShare/Enums/DatabaseType.cs
Normal file
8
WeddingShare/Enums/DatabaseType.cs
Normal file
@@ -0,0 +1,8 @@
|
||||
namespace WeddingShare.Enums
|
||||
{
|
||||
public enum DatabaseType
|
||||
{
|
||||
Unknown,
|
||||
SQLite
|
||||
}
|
||||
}
|
||||
9
WeddingShare/Enums/GalleryItemState.cs
Normal file
9
WeddingShare/Enums/GalleryItemState.cs
Normal file
@@ -0,0 +1,9 @@
|
||||
namespace WeddingShare.Enums
|
||||
{
|
||||
public enum GalleryItemState
|
||||
{
|
||||
Pending = 0,
|
||||
Approved = 1,
|
||||
All = 99
|
||||
}
|
||||
}
|
||||
10
WeddingShare/Enums/ImageOrientation.cs
Normal file
10
WeddingShare/Enums/ImageOrientation.cs
Normal file
@@ -0,0 +1,10 @@
|
||||
namespace WeddingShare.Enums
|
||||
{
|
||||
public enum ImageOrientation
|
||||
{
|
||||
None,
|
||||
Square,
|
||||
Portrait,
|
||||
Landscape
|
||||
}
|
||||
}
|
||||
@@ -16,11 +16,13 @@
|
||||
|
||||
public class ConfigHelper : IConfigHelper
|
||||
{
|
||||
private readonly IEnvironmentWrapper _environment;
|
||||
private readonly IConfiguration _configuration;
|
||||
private readonly ILogger<ConfigHelper> _logger;
|
||||
private readonly ILogger _logger;
|
||||
|
||||
public ConfigHelper(IConfiguration config, ILogger<ConfigHelper> logger)
|
||||
{
|
||||
public ConfigHelper(IEnvironmentWrapper environment, IConfiguration config, ILogger<ConfigHelper> logger)
|
||||
{
|
||||
_environment = environment;
|
||||
_configuration = config;
|
||||
_logger = logger;
|
||||
}
|
||||
@@ -29,8 +31,8 @@
|
||||
{
|
||||
try
|
||||
{
|
||||
var value = Environment.GetEnvironmentVariable(key.Replace(":", "_").ToUpper());
|
||||
if (!string.IsNullOrEmpty(value))
|
||||
var value = _environment.GetEnvironmentVariable(key.Replace(":", "_").ToUpper());
|
||||
if (!string.IsNullOrWhiteSpace(value))
|
||||
{
|
||||
return value;
|
||||
}
|
||||
@@ -47,8 +49,9 @@
|
||||
{
|
||||
try
|
||||
{
|
||||
var value = _configuration.GetValue<string>(!string.IsNullOrEmpty(section) ? $"{section}:{key}" : key);
|
||||
if (!string.IsNullOrEmpty(value))
|
||||
var configKey = !string.IsNullOrWhiteSpace(section) ? $"{section}:{key}" : key;
|
||||
var value = _configuration.GetValue<string>(configKey);
|
||||
if (!string.IsNullOrWhiteSpace(value))
|
||||
{
|
||||
return value;
|
||||
}
|
||||
@@ -66,13 +69,13 @@
|
||||
try
|
||||
{
|
||||
var value = !IsProtectedVariable($"{section}_{key}") ? this.GetEnvironmentVariable(key) : string.Empty;
|
||||
if (!string.IsNullOrEmpty(value))
|
||||
if (!string.IsNullOrWhiteSpace(value))
|
||||
{
|
||||
return value;
|
||||
}
|
||||
|
||||
value = this.GetConfigValue(section, key);
|
||||
if (!string.IsNullOrEmpty(value))
|
||||
if (!string.IsNullOrWhiteSpace(value))
|
||||
{
|
||||
return value;
|
||||
}
|
||||
@@ -90,7 +93,7 @@
|
||||
try
|
||||
{
|
||||
var value = this.Get(section, key);
|
||||
if (!string.IsNullOrEmpty(value))
|
||||
if (!string.IsNullOrWhiteSpace(value))
|
||||
{
|
||||
return value;
|
||||
}
|
||||
@@ -105,7 +108,7 @@
|
||||
try
|
||||
{
|
||||
var value = this.GetOrDefault(section, key, string.Empty);
|
||||
if (!string.IsNullOrEmpty(value))
|
||||
if (!string.IsNullOrWhiteSpace(value))
|
||||
{
|
||||
return Convert.ToInt32(value);
|
||||
}
|
||||
@@ -120,7 +123,7 @@
|
||||
try
|
||||
{
|
||||
var value = this.GetOrDefault(section, key, string.Empty);
|
||||
if (!string.IsNullOrEmpty(value))
|
||||
if (!string.IsNullOrWhiteSpace(value))
|
||||
{
|
||||
return Convert.ToInt64(value);
|
||||
}
|
||||
@@ -135,7 +138,7 @@
|
||||
try
|
||||
{
|
||||
var value = this.GetOrDefault(section, key, string.Empty);
|
||||
if (!string.IsNullOrEmpty(value))
|
||||
if (!string.IsNullOrWhiteSpace(value))
|
||||
{
|
||||
return Convert.ToDecimal(value);
|
||||
}
|
||||
@@ -150,7 +153,7 @@
|
||||
try
|
||||
{
|
||||
var value = this.GetOrDefault(section, key, string.Empty);
|
||||
if (!string.IsNullOrEmpty(value))
|
||||
if (!string.IsNullOrWhiteSpace(value))
|
||||
{
|
||||
return Convert.ToDouble(value);
|
||||
}
|
||||
@@ -165,7 +168,7 @@
|
||||
try
|
||||
{
|
||||
var value = this.GetOrDefault(section, key, string.Empty);
|
||||
if (!string.IsNullOrEmpty(value))
|
||||
if (!string.IsNullOrWhiteSpace(value))
|
||||
{
|
||||
return Convert.ToBoolean(value);
|
||||
}
|
||||
@@ -180,7 +183,7 @@
|
||||
try
|
||||
{
|
||||
var value = this.GetOrDefault(section, key, string.Empty);
|
||||
if (!string.IsNullOrEmpty(value))
|
||||
if (!string.IsNullOrWhiteSpace(value))
|
||||
{
|
||||
return Convert.ToDateTime(value);
|
||||
}
|
||||
|
||||
24
WeddingShare/Helpers/Database/IDatabaseHelper.cs
Normal file
24
WeddingShare/Helpers/Database/IDatabaseHelper.cs
Normal file
@@ -0,0 +1,24 @@
|
||||
using WeddingShare.Enums;
|
||||
using WeddingShare.Models.Database;
|
||||
|
||||
namespace WeddingShare.Helpers.Database
|
||||
{
|
||||
public interface IDatabaseHelper
|
||||
{
|
||||
Task<List<GalleryModel>> GetAllGalleries();
|
||||
Task<GalleryModel?> GetGallery(int id);
|
||||
Task<GalleryModel?> GetGallery(string name);
|
||||
Task<GalleryModel?> AddGallery(GalleryModel model);
|
||||
Task<GalleryModel?> EditGallery(GalleryModel model);
|
||||
Task<bool> DeleteGallery(GalleryModel model);
|
||||
|
||||
Task<List<GalleryItemModel>> GetAllGalleryItems(int galleryId, GalleryItemState state = GalleryItemState.All);
|
||||
Task<int> GetPendingGalleryItemCount(int? galleryId = null);
|
||||
Task<List<PendingGalleryItemModel>> GetPendingGalleryItems(int? galleryId = null);
|
||||
Task<PendingGalleryItemModel?> GetPendingGalleryItem(int id);
|
||||
Task<GalleryItemModel?> GetGalleryItem(int id);
|
||||
Task<GalleryItemModel?> AddGalleryItem(GalleryItemModel model);
|
||||
Task<GalleryItemModel?> EditGalleryItem(GalleryItemModel model);
|
||||
Task<bool> DeleteGalleryItem(GalleryItemModel model);
|
||||
}
|
||||
}
|
||||
500
WeddingShare/Helpers/Database/SQLiteDatabaseHelper.cs
Normal file
500
WeddingShare/Helpers/Database/SQLiteDatabaseHelper.cs
Normal file
@@ -0,0 +1,500 @@
|
||||
using System.Data;
|
||||
using System.Globalization;
|
||||
using Microsoft.Data.Sqlite;
|
||||
using Mono.TextTemplating;
|
||||
using WeddingShare.Enums;
|
||||
using WeddingShare.Models.Database;
|
||||
using YamlDotNet.Core.Tokens;
|
||||
|
||||
namespace WeddingShare.Helpers.Database
|
||||
{
|
||||
public class SQLiteDatabaseHelper : IDatabaseHelper
|
||||
{
|
||||
private readonly string _connString;
|
||||
private readonly ILogger _logger;
|
||||
|
||||
public SQLiteDatabaseHelper(IConfigHelper config, ILogger<SQLiteDatabaseHelper> logger)
|
||||
{
|
||||
_connString = config.GetOrDefault("Database", "Connection_String", "Data Source=./config/wedding-share.db");
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
#region Gallery
|
||||
public async Task<List<GalleryModel>> GetAllGalleries()
|
||||
{
|
||||
List<GalleryModel> result;
|
||||
|
||||
using (var conn = new SqliteConnection(_connString))
|
||||
{
|
||||
var cmd = new SqliteCommand($"SELECT g.*, COUNT(gi.`id`) AS `total`, SUM(CASE WHEN gi.`state`=@ApprovedState THEN 1 ELSE 0 END) AS `approved`, SUM(CASE WHEN gi.`state`=@PendingState THEN 1 ELSE 0 END) AS `pending` FROM `galleries` AS g LEFT JOIN `gallery_items` AS gi ON g.`id` = gi.`gallery_id` GROUP BY g.`id` ORDER BY `name` ASC;", conn);
|
||||
cmd.CommandType = CommandType.Text;
|
||||
cmd.Parameters.AddWithValue("PendingState", (int)GalleryItemState.Pending);
|
||||
cmd.Parameters.AddWithValue("ApprovedState", (int)GalleryItemState.Approved);
|
||||
|
||||
await conn.OpenAsync();
|
||||
result = await ReadGalleries(await cmd.ExecuteReaderAsync());
|
||||
await conn.CloseAsync();
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public async Task<GalleryModel?> GetGallery(int id)
|
||||
{
|
||||
GalleryModel? result;
|
||||
|
||||
using (var conn = new SqliteConnection(_connString))
|
||||
{
|
||||
var cmd = new SqliteCommand($"SELECT g.*, COUNT(gi.`id`) AS `total`, SUM(CASE WHEN gi.`state`=@ApprovedState THEN 1 ELSE 0 END) AS `approved`, SUM(CASE WHEN gi.`state`=@PendingState THEN 1 ELSE 0 END) AS `pending` FROM `galleries` AS g LEFT JOIN `gallery_items` AS gi ON g.`id` = gi.`gallery_id` WHERE g.`id`=@Id;", conn);
|
||||
cmd.CommandType = CommandType.Text;
|
||||
cmd.Parameters.AddWithValue("Id", id);
|
||||
cmd.Parameters.AddWithValue("PendingState", (int)GalleryItemState.Pending);
|
||||
cmd.Parameters.AddWithValue("ApprovedState", (int)GalleryItemState.Approved);
|
||||
|
||||
await conn.OpenAsync();
|
||||
result = (await ReadGalleries(await cmd.ExecuteReaderAsync()))?.FirstOrDefault();
|
||||
await conn.CloseAsync();
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public async Task<GalleryModel?> GetGallery(string name)
|
||||
{
|
||||
GalleryModel? result;
|
||||
|
||||
using (var conn = new SqliteConnection(_connString))
|
||||
{
|
||||
var cmd = new SqliteCommand($"SELECT g.*, COUNT(gi.`id`) AS `total`, SUM(CASE WHEN gi.`state`=@ApprovedState THEN 1 ELSE 0 END) AS `approved`, SUM(CASE WHEN gi.`state`=@PendingState THEN 1 ELSE 0 END) AS `pending` FROM `galleries` AS g LEFT JOIN `gallery_items` AS gi ON g.`id` = gi.`gallery_id` WHERE g.`name`=@Name;", conn);
|
||||
cmd.CommandType = CommandType.Text;
|
||||
cmd.Parameters.AddWithValue("Name", name?.ToLower());
|
||||
cmd.Parameters.AddWithValue("ApprovedState", (int)GalleryItemState.Approved);
|
||||
cmd.Parameters.AddWithValue("PendingState", (int)GalleryItemState.Pending);
|
||||
|
||||
await conn.OpenAsync();
|
||||
result = (await ReadGalleries(await cmd.ExecuteReaderAsync()))?.FirstOrDefault();
|
||||
await conn.CloseAsync();
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public async Task<GalleryModel?> AddGallery(GalleryModel model)
|
||||
{
|
||||
GalleryModel? result = null;
|
||||
|
||||
using (var conn = new SqliteConnection(_connString))
|
||||
{
|
||||
var cmd = new SqliteCommand($"INSERT INTO `galleries` (`name`, `secret_key`) VALUES (@Name, @SecretKey); SELECT g.*, COUNT(gi.`id`) AS `total`, SUM(CASE WHEN gi.`state`=@ApprovedState THEN 1 ELSE 0 END) AS `approved`, SUM(CASE WHEN gi.`state`=@PendingState THEN 1 ELSE 0 END) AS `pending` FROM `galleries` AS g LEFT JOIN `gallery_items` AS gi ON g.`id` = gi.`gallery_id` WHERE g.`id`=last_insert_rowid();", conn);
|
||||
cmd.CommandType = CommandType.Text;
|
||||
cmd.Parameters.AddWithValue("Name", model.Name.ToLower());
|
||||
cmd.Parameters.AddWithValue("SecretKey", !string.IsNullOrWhiteSpace(model.SecretKey) ? model.SecretKey : DBNull.Value);
|
||||
cmd.Parameters.AddWithValue("ApprovedState", (int)GalleryItemState.Approved);
|
||||
cmd.Parameters.AddWithValue("PendingState", (int)GalleryItemState.Pending);
|
||||
|
||||
await conn.OpenAsync();
|
||||
var tran = await conn.BeginTransactionAsync();
|
||||
try
|
||||
{
|
||||
cmd.Transaction = (SqliteTransaction)tran;
|
||||
result = (await ReadGalleries(await cmd.ExecuteReaderAsync()))?.FirstOrDefault();
|
||||
await tran.CommitAsync();
|
||||
}
|
||||
catch
|
||||
{
|
||||
await tran.RollbackAsync();
|
||||
}
|
||||
|
||||
await conn.CloseAsync();
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public async Task<GalleryModel?> EditGallery(GalleryModel model)
|
||||
{
|
||||
GalleryModel? result = null;
|
||||
|
||||
using (var conn = new SqliteConnection(_connString))
|
||||
{
|
||||
var cmd = new SqliteCommand($"UPDATE `galleries` SET `name`=@Name, `secret_key`=@SecretKey WHERE `id`=@Id; SELECT g.*, COUNT(gi.`id`) AS `total`, SUM(CASE WHEN gi.`state`=@ApprovedState THEN 1 ELSE 0 END) AS `approved`, SUM(CASE WHEN gi.`state`=@PendingState THEN 1 ELSE 0 END) AS `pending` FROM `galleries` AS g LEFT JOIN `gallery_items` AS gi ON g.`id` = gi.`gallery_id` WHERE g.`id`=@Id;", conn);
|
||||
cmd.CommandType = CommandType.Text;
|
||||
cmd.Parameters.AddWithValue("Id", model.Id);
|
||||
cmd.Parameters.AddWithValue("Name", model.Name?.ToLower());
|
||||
cmd.Parameters.AddWithValue("SecretKey", !string.IsNullOrWhiteSpace(model.SecretKey) ? model.SecretKey : DBNull.Value);
|
||||
cmd.Parameters.AddWithValue("ApprovedState", (int)GalleryItemState.Approved);
|
||||
cmd.Parameters.AddWithValue("PendingState", (int)GalleryItemState.Pending);
|
||||
|
||||
await conn.OpenAsync();
|
||||
var tran = await conn.BeginTransactionAsync();
|
||||
try
|
||||
{
|
||||
cmd.Transaction = (SqliteTransaction)tran;
|
||||
result = (await ReadGalleries(await cmd.ExecuteReaderAsync()))?.FirstOrDefault();
|
||||
await tran.CommitAsync();
|
||||
}
|
||||
catch
|
||||
{
|
||||
await tran.RollbackAsync();
|
||||
}
|
||||
|
||||
await conn.CloseAsync();
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public async Task<bool> DeleteGallery(GalleryModel model)
|
||||
{
|
||||
bool result = false;
|
||||
|
||||
using (var conn = new SqliteConnection(_connString))
|
||||
{
|
||||
var cmd = new SqliteCommand($"DELETE FROM `gallery_items` WHERE `gallery_id`=@Id; DELETE FROM `galleries` WHERE `id`=@Id;", conn);
|
||||
cmd.CommandType = CommandType.Text;
|
||||
cmd.Parameters.AddWithValue("Id", model.Id);
|
||||
|
||||
await conn.OpenAsync();
|
||||
var tran = await conn.BeginTransactionAsync();
|
||||
try
|
||||
{
|
||||
cmd.Transaction = (SqliteTransaction)tran;
|
||||
result = (await cmd.ExecuteNonQueryAsync()) > 0;
|
||||
await tran.CommitAsync();
|
||||
}
|
||||
catch
|
||||
{
|
||||
await tran.RollbackAsync();
|
||||
}
|
||||
|
||||
await conn.CloseAsync();
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Gallery Items
|
||||
public async Task<List<GalleryItemModel>> GetAllGalleryItems(int galleryId, GalleryItemState state = GalleryItemState.All)
|
||||
{
|
||||
List<GalleryItemModel> result;
|
||||
|
||||
using (var conn = new SqliteConnection(_connString))
|
||||
{
|
||||
var cmd = new SqliteCommand($"SELECT * FROM `gallery_items` WHERE `gallery_id`=@Id {(state != GalleryItemState.All ? "AND `state`=@State" : string.Empty)} ORDER BY `id` ASC;", conn);
|
||||
cmd.CommandType = CommandType.Text;
|
||||
cmd.Parameters.AddWithValue("Id", galleryId);
|
||||
cmd.Parameters.AddWithValue("State", state);
|
||||
|
||||
|
||||
await conn.OpenAsync();
|
||||
result = await ReadGalleryItems(await cmd.ExecuteReaderAsync());
|
||||
await conn.CloseAsync();
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public async Task<List<PendingGalleryItemModel>> GetPendingGalleryItems(int? galleryId = null)
|
||||
{
|
||||
List<PendingGalleryItemModel> result;
|
||||
|
||||
using (var conn = new SqliteConnection(_connString))
|
||||
{
|
||||
var cmd = new SqliteCommand($"SELECT g.`name` AS `gallery_name`, gi.* FROM `gallery_items` AS gi LEFT JOIN `galleries` AS g ON g.`id` = gi.`gallery_id` WHERE gi.`state`=@State {(galleryId != null ? "AND gi.`gallery_id`=@GalleryId" : string.Empty)};", conn);
|
||||
cmd.CommandType = CommandType.Text;
|
||||
cmd.Parameters.AddWithValue("GalleryId", galleryId);
|
||||
cmd.Parameters.AddWithValue("State", (int)GalleryItemState.Pending);
|
||||
|
||||
await conn.OpenAsync();
|
||||
result = await ReadPendingGalleryItems(await cmd.ExecuteReaderAsync());
|
||||
await conn.CloseAsync();
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public async Task<PendingGalleryItemModel?> GetPendingGalleryItem(int id)
|
||||
{
|
||||
PendingGalleryItemModel? result;
|
||||
|
||||
using (var conn = new SqliteConnection(_connString))
|
||||
{
|
||||
var cmd = new SqliteCommand($"SELECT g.`name` AS `gallery_name`, gi.* FROM `gallery_items` AS gi LEFT JOIN `galleries` AS g ON g.`id` = gi.`gallery_id` WHERE gi.`id`=@Id;", conn);
|
||||
cmd.CommandType = CommandType.Text;
|
||||
cmd.Parameters.AddWithValue("Id", id);
|
||||
|
||||
await conn.OpenAsync();
|
||||
result = (await ReadPendingGalleryItems(await cmd.ExecuteReaderAsync())).FirstOrDefault();
|
||||
await conn.CloseAsync();
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public async Task<int> GetPendingGalleryItemCount(int? galleryId = null)
|
||||
{
|
||||
int result = 0;
|
||||
|
||||
using (var conn = new SqliteConnection(_connString))
|
||||
{
|
||||
var cmd = new SqliteCommand($"SELECT COUNT(`id`) FROM `gallery_items` {(galleryId != null ? "WHERE `gallery_id`=@GalleryId" : string.Empty)};", conn);
|
||||
cmd.CommandType = CommandType.Text;
|
||||
cmd.Parameters.AddWithValue("GalleryId", galleryId);
|
||||
|
||||
|
||||
await conn.OpenAsync();
|
||||
result = (int)(await cmd.ExecuteScalarAsync() ?? 0);
|
||||
await conn.CloseAsync();
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public async Task<GalleryItemModel?> GetGalleryItem(int id)
|
||||
{
|
||||
GalleryItemModel? result;
|
||||
|
||||
using (var conn = new SqliteConnection(_connString))
|
||||
{
|
||||
var cmd = new SqliteCommand($"SELECT * FROM `gallery_items` WHERE `id`=@Id;", conn);
|
||||
cmd.CommandType = CommandType.Text;
|
||||
cmd.Parameters.AddWithValue("Id", id);
|
||||
|
||||
await conn.OpenAsync();
|
||||
result = (await ReadGalleryItems(await cmd.ExecuteReaderAsync()))?.FirstOrDefault();
|
||||
await conn.CloseAsync();
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public async Task<GalleryItemModel?> AddGalleryItem(GalleryItemModel model)
|
||||
{
|
||||
GalleryItemModel? result = null;
|
||||
|
||||
using (var conn = new SqliteConnection(_connString))
|
||||
{
|
||||
var cmd = new SqliteCommand($"INSERT INTO `gallery_items` (`gallery_id`, `title`, `state`) VALUES (@GalleryId, @Title, @State); SELECT * FROM `gallery_items` WHERE `id`=last_insert_rowid();", conn);
|
||||
cmd.CommandType = CommandType.Text;
|
||||
cmd.Parameters.AddWithValue("GalleryId", model.GalleryId);
|
||||
cmd.Parameters.AddWithValue("Title", model.Title);
|
||||
cmd.Parameters.AddWithValue("State", (int)model.State);
|
||||
|
||||
await conn.OpenAsync();
|
||||
var tran = await conn.BeginTransactionAsync();
|
||||
try
|
||||
{
|
||||
cmd.Transaction = (SqliteTransaction)tran;
|
||||
result = (await ReadGalleryItems(await cmd.ExecuteReaderAsync()))?.FirstOrDefault();
|
||||
await tran.CommitAsync();
|
||||
}
|
||||
catch
|
||||
{
|
||||
await tran.RollbackAsync();
|
||||
}
|
||||
|
||||
await conn.CloseAsync();
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public async Task<GalleryItemModel?> EditGalleryItem(GalleryItemModel model)
|
||||
{
|
||||
GalleryItemModel? result = null;
|
||||
|
||||
using (var conn = new SqliteConnection(_connString))
|
||||
{
|
||||
var cmd = new SqliteCommand($"UPDATE `gallery_items` SET `title`=@Title, `state`=@State WHERE `id`=@Id; SELECT * FROM `gallery_items` WHERE `id`=@Id;", conn);
|
||||
cmd.CommandType = CommandType.Text;
|
||||
cmd.Parameters.AddWithValue("Id", model.Id);
|
||||
cmd.Parameters.AddWithValue("Title", model.Title);
|
||||
cmd.Parameters.AddWithValue("State", (int)model.State);
|
||||
|
||||
await conn.OpenAsync();
|
||||
var tran = await conn.BeginTransactionAsync();
|
||||
try
|
||||
{
|
||||
cmd.Transaction = (SqliteTransaction)tran;
|
||||
result = (await ReadGalleryItems(await cmd.ExecuteReaderAsync()))?.FirstOrDefault();
|
||||
await tran.CommitAsync();
|
||||
}
|
||||
catch
|
||||
{
|
||||
await tran.RollbackAsync();
|
||||
}
|
||||
|
||||
await conn.CloseAsync();
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public async Task<bool> DeleteGalleryItem(GalleryItemModel model)
|
||||
{
|
||||
bool result = false;
|
||||
|
||||
using (var conn = new SqliteConnection(_connString))
|
||||
{
|
||||
var cmd = new SqliteCommand($"DELETE FROM `gallery_items` WHERE `id`=@Id;", conn);
|
||||
cmd.CommandType = CommandType.Text;
|
||||
cmd.Parameters.AddWithValue("Id", model.Id);
|
||||
|
||||
await conn.OpenAsync();
|
||||
var tran = await conn.BeginTransactionAsync();
|
||||
try
|
||||
{
|
||||
cmd.Transaction = (SqliteTransaction)tran;
|
||||
result = (await cmd.ExecuteNonQueryAsync()) > 0;
|
||||
await tran.CommitAsync();
|
||||
}
|
||||
catch
|
||||
{
|
||||
await tran.RollbackAsync();
|
||||
}
|
||||
|
||||
await conn.CloseAsync();
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Data Parsers
|
||||
private async Task<List<GalleryModel>> ReadGalleries(SqliteDataReader? reader)
|
||||
{
|
||||
var items = new List<GalleryModel>();
|
||||
|
||||
if (reader != null && reader.HasRows)
|
||||
{
|
||||
while (reader.Read())
|
||||
{
|
||||
try
|
||||
{
|
||||
var id = !await reader.IsDBNullAsync("id") ? reader.GetInt32("id") : 0;
|
||||
if (id > 0)
|
||||
{
|
||||
items.Add(new GalleryModel()
|
||||
{
|
||||
Id = id,
|
||||
Name = !await reader.IsDBNullAsync("name") ? reader.GetString("name") : null,
|
||||
SecretKey = !await reader.IsDBNullAsync("secret_key") ? reader.GetString("secret_key") : null,
|
||||
TotalItems = !await reader.IsDBNullAsync("total") ? reader.GetInt32("total") : 0,
|
||||
ApprovedItems = !await reader.IsDBNullAsync("approved") ? reader.GetInt32("approved") : 0,
|
||||
PendingItems = !await reader.IsDBNullAsync("pending") ? reader.GetInt32("pending") : 0,
|
||||
});
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogWarning(ex, $"Failed to parse gallery model from database - {ex?.Message}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return items;
|
||||
}
|
||||
|
||||
private async Task<List<GalleryItemModel>> ReadGalleryItems(SqliteDataReader? reader)
|
||||
{
|
||||
var items = new List<GalleryItemModel>();
|
||||
|
||||
if (reader != null && reader.HasRows)
|
||||
{
|
||||
while (reader.Read())
|
||||
{
|
||||
try
|
||||
{
|
||||
var id = !await reader.IsDBNullAsync("id") ? reader.GetInt32("id") : 0;
|
||||
if (id > 0)
|
||||
{
|
||||
items.Add(new GalleryItemModel()
|
||||
{
|
||||
Id = id,
|
||||
GalleryId = !await reader.IsDBNullAsync("gallery_id") ? reader.GetInt32("gallery_id") : 0,
|
||||
Title = !await reader.IsDBNullAsync("title") ? reader.GetString("title") : string.Empty,
|
||||
UploadedBy = !await reader.IsDBNullAsync("uploaded_by") ? reader.GetString("uploaded_by") : null,
|
||||
State = !await reader.IsDBNullAsync("state") ? (GalleryItemState)reader.GetInt32("state") : GalleryItemState.Pending
|
||||
});
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogWarning(ex, $"Failed to parse gallery item model from database - {ex?.Message}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return items;
|
||||
}
|
||||
|
||||
private async Task<List<PendingGalleryItemModel>> ReadPendingGalleryItems(SqliteDataReader? reader)
|
||||
{
|
||||
var items = new List<PendingGalleryItemModel>();
|
||||
|
||||
if (reader != null && reader.HasRows)
|
||||
{
|
||||
while (reader.Read())
|
||||
{
|
||||
try
|
||||
{
|
||||
|
||||
var id = !await reader.IsDBNullAsync("id") ? reader.GetInt32("id") : 0;
|
||||
if (id > 0)
|
||||
{
|
||||
items.Add(new PendingGalleryItemModel()
|
||||
{
|
||||
Id = id,
|
||||
GalleryId = !await reader.IsDBNullAsync("gallery_id") ? reader.GetInt32("gallery_id") : 0,
|
||||
GalleryName = !await reader.IsDBNullAsync("gallery_name") ? reader.GetString("gallery_name") : "default",
|
||||
Title = !await reader.IsDBNullAsync("title") ? reader.GetString("title") : string.Empty,
|
||||
UploadedBy = !await reader.IsDBNullAsync("uploaded_by") ? reader.GetString("uploaded_by") : null,
|
||||
State = !await reader.IsDBNullAsync("state") ? (GalleryItemState)reader.GetInt32("state") : GalleryItemState.Pending
|
||||
});
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogWarning(ex, $"Failed to parse pending gallery item model from database - {ex?.Message}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return items;
|
||||
}
|
||||
|
||||
private async Task<List<UserModel>> ReadUsers(SqliteDataReader? reader)
|
||||
{
|
||||
var items = new List<UserModel>();
|
||||
|
||||
if (reader != null && reader.HasRows)
|
||||
{
|
||||
while (reader.Read())
|
||||
{
|
||||
try
|
||||
{
|
||||
var id = !await reader.IsDBNullAsync("id") ? reader.GetInt32("id") : 0;
|
||||
if (id > 0)
|
||||
{
|
||||
items.Add(new UserModel()
|
||||
{
|
||||
Id = id,
|
||||
Name = !await reader.IsDBNullAsync("name") ? reader.GetString("name") : null,
|
||||
Email = !await reader.IsDBNullAsync("email") ? reader.GetString("email") : null,
|
||||
Password = !await reader.IsDBNullAsync("password") ? reader.GetString("password") : null
|
||||
});
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogWarning(ex, $"Failed to parse user model from database - {ex?.Message}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return items;
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
75
WeddingShare/Helpers/Dbup/DbupHelper.cs
Normal file
75
WeddingShare/Helpers/Dbup/DbupHelper.cs
Normal file
@@ -0,0 +1,75 @@
|
||||
using System.Reflection;
|
||||
using DbUp;
|
||||
using DbUp.Engine;
|
||||
using WeddingShare.Enums;
|
||||
|
||||
namespace WeddingShare.Helpers.Dbup
|
||||
{
|
||||
public sealed class DbupMigrator(IEnvironmentWrapper environment, IConfiguration configuration, ILoggerFactory loggerFactory) : BackgroundService
|
||||
{
|
||||
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
|
||||
{
|
||||
await Task.Run(() =>
|
||||
{
|
||||
var logger = loggerFactory.CreateLogger<DbupMigrator>();
|
||||
|
||||
if (!Directory.Exists("config"))
|
||||
{
|
||||
Directory.CreateDirectory("config");
|
||||
}
|
||||
|
||||
var config = new ConfigHelper(environment, configuration, loggerFactory.CreateLogger<ConfigHelper>());
|
||||
var connString = config.GetOrDefault("Database", "Connection_String", "Data Source=./config/wedding-share.db");
|
||||
if (!string.IsNullOrWhiteSpace(connString))
|
||||
{
|
||||
DatabaseUpgradeResult? dbupResult;
|
||||
|
||||
var dbType = config.GetOrDefault("Database", "Database_Type", "sqlite")?.ToLower();
|
||||
switch (dbType)
|
||||
{
|
||||
case "sqlite":
|
||||
dbupResult = new DbupSqliteHelper().Migrate(connString);
|
||||
break;
|
||||
default:
|
||||
var error = $"Database type '{dbType}' is not yet supported by this application";
|
||||
logger.LogWarning(error);
|
||||
throw new NotImplementedException(error);
|
||||
}
|
||||
|
||||
if (dbupResult != null && !dbupResult.Successful)
|
||||
{
|
||||
logger.LogWarning($"DBUP failed with error: '{dbupResult?.Error?.Message}' - '{dbupResult?.Error?.ToString()}'");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
logger.LogError($"DBUP failed with error: 'Connection string was null or empty'");
|
||||
throw new ArgumentNullException("Please specify a valid database connection string");
|
||||
}
|
||||
}, stoppingToken);
|
||||
}
|
||||
}
|
||||
|
||||
public class DbupSqliteHelper
|
||||
{
|
||||
public DatabaseUpgradeResult Migrate(string connectionString)
|
||||
{
|
||||
try
|
||||
{
|
||||
var dbupBuilder = DeployChanges.To
|
||||
.SQLiteDatabase(connectionString)
|
||||
.WithScriptsEmbeddedInAssembly(Assembly.GetExecutingAssembly())
|
||||
.WithScriptNameComparer(new DbupScriptComparer())
|
||||
.WithFilter(new DbupScriptFilter(DatabaseType.SQLite))
|
||||
.LogToConsole();
|
||||
dbupBuilder.Configure(c => c.Journal = new DbupTableJournal(() => c.ConnectionManager, () => c.Log, "schemaversions"));
|
||||
|
||||
return dbupBuilder.Build().PerformUpgrade();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return new DatabaseUpgradeResult(null, false, ex, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
31
WeddingShare/Helpers/Dbup/DbupScriptComparer.cs
Normal file
31
WeddingShare/Helpers/Dbup/DbupScriptComparer.cs
Normal file
@@ -0,0 +1,31 @@
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
|
||||
namespace WeddingShare.Helpers.Dbup
|
||||
{
|
||||
public class DbupScriptComparer : IComparer<string>
|
||||
{
|
||||
public DbupScriptComparer()
|
||||
{
|
||||
}
|
||||
|
||||
public int Compare([AllowNull] string x, [AllowNull] string y)
|
||||
{
|
||||
return GetFileName(x).ToLower().CompareTo(GetFileName(y).ToLower());
|
||||
}
|
||||
|
||||
private string GetFileName(string name)
|
||||
{
|
||||
try
|
||||
{
|
||||
var parts = name.Split('.', StringSplitOptions.RemoveEmptyEntries);
|
||||
if (parts != null && parts.Length >= 2)
|
||||
{
|
||||
return string.Join(".", parts.Skip(parts.Length - 2).Take(2));
|
||||
}
|
||||
}
|
||||
catch { }
|
||||
|
||||
return name;
|
||||
}
|
||||
}
|
||||
}
|
||||
28
WeddingShare/Helpers/Dbup/DbupScriptFilter.cs
Normal file
28
WeddingShare/Helpers/Dbup/DbupScriptFilter.cs
Normal file
@@ -0,0 +1,28 @@
|
||||
using DbUp.Engine;
|
||||
using DbUp.Support;
|
||||
using WeddingShare.Enums;
|
||||
|
||||
namespace WeddingShare.Helpers.Dbup
|
||||
{
|
||||
public class DbupScriptFilter : IScriptFilter
|
||||
{
|
||||
private readonly DatabaseType _dbType;
|
||||
|
||||
public DbupScriptFilter(DatabaseType dbType)
|
||||
{
|
||||
_dbType = dbType;
|
||||
}
|
||||
|
||||
public IEnumerable<SqlScript> Filter(IEnumerable<SqlScript> sorted, HashSet<string> executedScriptNames, ScriptNameComparer comparer)
|
||||
{
|
||||
var scripts = sorted.Where(s => s.SqlScriptOptions.ScriptType == ScriptType.RunAlways || !executedScriptNames.Contains(s.Name, comparer));
|
||||
switch (_dbType)
|
||||
{
|
||||
case DatabaseType.SQLite:
|
||||
return scripts.Where(s => s.Name.ToLower().Contains(".sqlscripts.sqlite."));
|
||||
default:
|
||||
return new List<SqlScript>();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
33
WeddingShare/Helpers/Dbup/DbupTableJournal.cs
Normal file
33
WeddingShare/Helpers/Dbup/DbupTableJournal.cs
Normal file
@@ -0,0 +1,33 @@
|
||||
using System.Data;
|
||||
using DbUp.Engine;
|
||||
using DbUp.Engine.Output;
|
||||
using DbUp.Engine.Transactions;
|
||||
using DbUp.SQLite;
|
||||
|
||||
namespace WeddingShare.Helpers.Dbup
|
||||
{
|
||||
public class DbupTableJournal : SQLiteTableJournal
|
||||
{
|
||||
public DbupTableJournal(Func<IConnectionManager> connectionManager, Func<IUpgradeLog> logger, string table)
|
||||
: base(connectionManager, logger, table)
|
||||
{
|
||||
}
|
||||
|
||||
public override void StoreExecutedScript(SqlScript script, Func<IDbCommand> dbCommandFactory)
|
||||
{
|
||||
var scriptName = script.Name;
|
||||
|
||||
try
|
||||
{
|
||||
var parts = script.Name.Split('.', StringSplitOptions.RemoveEmptyEntries);
|
||||
if (parts != null && parts.Length >= 2)
|
||||
{
|
||||
scriptName = string.Join(".", parts.Skip(parts.Length - 2).Take(2));
|
||||
}
|
||||
}
|
||||
catch { }
|
||||
|
||||
base.StoreExecutedScript(new SqlScript(scriptName, script.Contents), dbCommandFactory);
|
||||
}
|
||||
}
|
||||
}
|
||||
139
WeddingShare/Helpers/DirectoryScanner.cs
Normal file
139
WeddingShare/Helpers/DirectoryScanner.cs
Normal file
@@ -0,0 +1,139 @@
|
||||
using NCrontab;
|
||||
using WeddingShare.Enums;
|
||||
using WeddingShare.Helpers.Database;
|
||||
using WeddingShare.Models.Database;
|
||||
|
||||
namespace WeddingShare.Helpers
|
||||
{
|
||||
public sealed class DirectoryScanner(IWebHostEnvironment hostingEnvironment, IConfigHelper configHelper, IDatabaseHelper databaseHelper, IImageHelper imageHelper, ILogger<DirectoryScanner> logger) : BackgroundService
|
||||
{
|
||||
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
|
||||
{
|
||||
var cron = configHelper.GetOrDefault("BackgroundServices", "Directory_Scanner_Interval", "*/30 * * * *");
|
||||
var schedule = CrontabSchedule.Parse(cron);
|
||||
|
||||
await Task.Delay((int)TimeSpan.FromSeconds(10).TotalMilliseconds, stoppingToken);
|
||||
await ScanForFiles();
|
||||
|
||||
while (!stoppingToken.IsCancellationRequested)
|
||||
{
|
||||
var now = DateTime.Now;
|
||||
var nextExecutionTime = schedule.GetNextOccurrence(now);
|
||||
var waitTime = nextExecutionTime - now;
|
||||
await Task.Delay(waitTime, stoppingToken);
|
||||
|
||||
await ScanForFiles();
|
||||
}
|
||||
}
|
||||
|
||||
private async Task ScanForFiles()
|
||||
{
|
||||
await Task.Run(async () =>
|
||||
{
|
||||
var allowedFileTypes = configHelper.GetOrDefault("Settings", "Allowed_File_Types", ".jpg,.jpeg,.png").Split(',', StringSplitOptions.TrimEntries | StringSplitOptions.RemoveEmptyEntries);
|
||||
|
||||
var thumbnailsDirectory = Path.Combine(hostingEnvironment.WebRootPath, "thumbnails");
|
||||
if (!Directory.Exists(thumbnailsDirectory))
|
||||
{
|
||||
Directory.CreateDirectory(thumbnailsDirectory);
|
||||
}
|
||||
|
||||
var uploadsDirectory = Path.Combine(hostingEnvironment.WebRootPath, "uploads");
|
||||
if (Directory.Exists(uploadsDirectory))
|
||||
{
|
||||
var searchPattern = !configHelper.GetOrDefault("Settings", "Single_Gallery_Mode", false) ? "*" : "default";
|
||||
var galleries = Directory.GetDirectories(uploadsDirectory, searchPattern, SearchOption.TopDirectoryOnly)?.Where(x => !Path.GetFileName(x).StartsWith("."));
|
||||
if (galleries != null)
|
||||
{
|
||||
foreach (var gallery in galleries)
|
||||
{
|
||||
try
|
||||
{
|
||||
var id = Path.GetFileName(gallery).ToLower();
|
||||
var galleryItem = await databaseHelper.GetGallery(id);
|
||||
if (galleryItem == null)
|
||||
{
|
||||
galleryItem = await databaseHelper.AddGallery(new GalleryModel()
|
||||
{
|
||||
Name = id
|
||||
});
|
||||
}
|
||||
|
||||
if (galleryItem != null)
|
||||
{
|
||||
var galleryItems = await databaseHelper.GetAllGalleryItems(galleryItem.Id);
|
||||
|
||||
if (Path.Exists(gallery))
|
||||
{
|
||||
var approvedFiles = Directory.GetFiles(gallery, "*.*", SearchOption.TopDirectoryOnly).Where(x => allowedFileTypes.Any(y => string.Equals(Path.GetExtension(x).Trim('.'), y.Trim('.'), StringComparison.OrdinalIgnoreCase)));
|
||||
if (approvedFiles != null)
|
||||
{
|
||||
foreach (var file in approvedFiles)
|
||||
{
|
||||
try
|
||||
{
|
||||
var filename = Path.GetFileName(file);
|
||||
if (!galleryItems.Exists(x => string.Equals(x.Title, filename, StringComparison.OrdinalIgnoreCase)))
|
||||
{
|
||||
await databaseHelper.AddGalleryItem(new GalleryItemModel()
|
||||
{
|
||||
GalleryId = galleryItem.Id,
|
||||
Title = filename,
|
||||
State = GalleryItemState.Approved
|
||||
});
|
||||
}
|
||||
|
||||
var thumbnailPath = Path.Combine(thumbnailsDirectory, $"{Path.GetFileNameWithoutExtension(file)}.webp");
|
||||
if (!File.Exists(thumbnailPath))
|
||||
{
|
||||
await imageHelper.GenerateThumbnail(file, thumbnailPath, configHelper.GetOrDefault("Settings", "Thumbnail_Size", 720));
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.LogError(ex, $"An error occurred while scanning file '{file}'");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (Path.Exists(Path.Combine(gallery, "Pending")))
|
||||
{
|
||||
var pendingFiles = Directory.GetFiles(Path.Combine(gallery, "Pending"), "*.*", SearchOption.TopDirectoryOnly).Where(x => allowedFileTypes.Any(y => string.Equals(Path.GetExtension(x).Trim('.'), y.Trim('.'), StringComparison.OrdinalIgnoreCase)));
|
||||
if (pendingFiles != null)
|
||||
{
|
||||
foreach (var file in pendingFiles)
|
||||
{
|
||||
try
|
||||
{
|
||||
var filename = Path.GetFileName(file);
|
||||
if (!galleryItems.Exists(x => string.Equals(x.Title, filename, StringComparison.OrdinalIgnoreCase)))
|
||||
{
|
||||
await databaseHelper.AddGalleryItem(new GalleryItemModel()
|
||||
{
|
||||
GalleryId = galleryItem.Id,
|
||||
Title = filename,
|
||||
State = GalleryItemState.Pending
|
||||
});
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.LogError(ex, $"An error occurred while scanning file '{file}'");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.LogError(ex, $"An error occurred while scanning directory '{gallery}'");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
15
WeddingShare/Helpers/EnvironmentWrapper.cs
Normal file
15
WeddingShare/Helpers/EnvironmentWrapper.cs
Normal file
@@ -0,0 +1,15 @@
|
||||
namespace WeddingShare.Helpers
|
||||
{
|
||||
public interface IEnvironmentWrapper
|
||||
{
|
||||
string? GetEnvironmentVariable(string variable);
|
||||
}
|
||||
|
||||
public class EnvironmentWrapper : IEnvironmentWrapper
|
||||
{
|
||||
public string? GetEnvironmentVariable(string variable)
|
||||
{
|
||||
return Environment.GetEnvironmentVariable(variable);
|
||||
}
|
||||
}
|
||||
}
|
||||
10
WeddingShare/Helpers/ErrorHelper.cs
Normal file
10
WeddingShare/Helpers/ErrorHelper.cs
Normal file
@@ -0,0 +1,10 @@
|
||||
namespace WeddingShare.Helpers
|
||||
{
|
||||
public static class ErrorCode
|
||||
{
|
||||
public const int UnexpectedError = 400;
|
||||
public const int Unauthorized = 401;
|
||||
public const int InvalidSecretKey = 402;
|
||||
public const int GalleryCreationNotAllowed = 403;
|
||||
}
|
||||
}
|
||||
89
WeddingShare/Helpers/ImageHelper.cs
Normal file
89
WeddingShare/Helpers/ImageHelper.cs
Normal file
@@ -0,0 +1,89 @@
|
||||
using SixLabors.ImageSharp;
|
||||
using SixLabors.ImageSharp.Processing;
|
||||
using WeddingShare.Enums;
|
||||
|
||||
namespace WeddingShare.Helpers
|
||||
{
|
||||
public interface IImageHelper
|
||||
{
|
||||
Task<bool> GenerateThumbnail(string imagePath, string savePath, int size = 720);
|
||||
ImageOrientation GetOrientation(Image img);
|
||||
}
|
||||
|
||||
public class ImageHelper : IImageHelper
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
|
||||
public ImageHelper(ILogger<ImageHelper> logger)
|
||||
{
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public async Task<bool> GenerateThumbnail(string imagePath, string savePath, int size = 720)
|
||||
{
|
||||
if (File.Exists(imagePath))
|
||||
{
|
||||
try
|
||||
{
|
||||
var filename = Path.GetFileName(imagePath);
|
||||
using (var img = await Image.LoadAsync(imagePath))
|
||||
{
|
||||
var width = 0;
|
||||
var height = 0;
|
||||
|
||||
var orientation = this.GetOrientation(img);
|
||||
if (orientation == ImageOrientation.Square)
|
||||
{
|
||||
width = size;
|
||||
height = size;
|
||||
}
|
||||
else if (orientation == ImageOrientation.Landscape)
|
||||
{
|
||||
var scale = (decimal)size / (decimal)img.Width;
|
||||
width = (int)((decimal)img.Width * scale);
|
||||
height = (int)((decimal)img.Height * scale);
|
||||
}
|
||||
else if (orientation == ImageOrientation.Portrait)
|
||||
{
|
||||
var scale = (decimal)size / (decimal)img.Height;
|
||||
width = (int)((decimal)img.Width * scale);
|
||||
height = (int)((decimal)img.Height * scale);
|
||||
}
|
||||
|
||||
img.Mutate(x => x.Resize(width, height));
|
||||
await img.SaveAsWebpAsync(savePath);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogWarning(ex, $"Failed to generate thumbnail");
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public ImageOrientation GetOrientation(Image img)
|
||||
{
|
||||
if (img != null)
|
||||
{
|
||||
if (img.Width > img.Height)
|
||||
{
|
||||
return ImageOrientation.Landscape;
|
||||
}
|
||||
else if (img.Width < img.Height)
|
||||
{
|
||||
return ImageOrientation.Portrait;
|
||||
}
|
||||
else if (img.Width == img.Height)
|
||||
{
|
||||
return ImageOrientation.Square;
|
||||
}
|
||||
}
|
||||
|
||||
return ImageOrientation.None;
|
||||
}
|
||||
}
|
||||
}
|
||||
43
WeddingShare/Helpers/SecretKeyHelper.cs
Normal file
43
WeddingShare/Helpers/SecretKeyHelper.cs
Normal file
@@ -0,0 +1,43 @@
|
||||
using WeddingShare.Helpers.Database;
|
||||
|
||||
namespace WeddingShare.Helpers
|
||||
{
|
||||
public interface ISecretKeyHelper
|
||||
{
|
||||
Task<string?> GetGallerySecretKey(string galleryId);
|
||||
}
|
||||
|
||||
public class SecretKeyHelper : ISecretKeyHelper
|
||||
{
|
||||
private readonly IConfigHelper _config;
|
||||
private readonly IDatabaseHelper _database;
|
||||
|
||||
public SecretKeyHelper(IConfigHelper config, IDatabaseHelper database)
|
||||
{
|
||||
_config = config;
|
||||
_database = database;
|
||||
}
|
||||
|
||||
public async Task<string?> GetGallerySecretKey(string galleryId)
|
||||
{
|
||||
try
|
||||
{
|
||||
var secretKey = _config.Get("Settings", $"Secret_Key_{galleryId}");
|
||||
if (string.IsNullOrWhiteSpace(secretKey))
|
||||
{
|
||||
secretKey = (await _database.GetGallery(galleryId))?.SecretKey;
|
||||
if (string.IsNullOrWhiteSpace(secretKey))
|
||||
{
|
||||
secretKey = _config.Get("Settings", "Secret_Key");
|
||||
}
|
||||
}
|
||||
|
||||
return secretKey;
|
||||
}
|
||||
catch
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
13
WeddingShare/Models/Database/GalleryItemModel.cs
Normal file
13
WeddingShare/Models/Database/GalleryItemModel.cs
Normal file
@@ -0,0 +1,13 @@
|
||||
using WeddingShare.Enums;
|
||||
|
||||
namespace WeddingShare.Models.Database
|
||||
{
|
||||
public class GalleryItemModel
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public int GalleryId { get; set; }
|
||||
public string Title { get; set; }
|
||||
public string? UploadedBy { get; set; }
|
||||
public GalleryItemState State { get; set; }
|
||||
}
|
||||
}
|
||||
12
WeddingShare/Models/Database/GalleryModel.cs
Normal file
12
WeddingShare/Models/Database/GalleryModel.cs
Normal file
@@ -0,0 +1,12 @@
|
||||
namespace WeddingShare.Models.Database
|
||||
{
|
||||
public class GalleryModel
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public string Name { get; set; }
|
||||
public string? SecretKey { get; set; }
|
||||
public int TotalItems { get; set; }
|
||||
public int ApprovedItems { get; set; }
|
||||
public int PendingItems { get; set; }
|
||||
}
|
||||
}
|
||||
7
WeddingShare/Models/Database/PendingGalleryItemModel.cs
Normal file
7
WeddingShare/Models/Database/PendingGalleryItemModel.cs
Normal file
@@ -0,0 +1,7 @@
|
||||
namespace WeddingShare.Models.Database
|
||||
{
|
||||
public class PendingGalleryItemModel : GalleryItemModel
|
||||
{
|
||||
public string GalleryName { get; set; }
|
||||
}
|
||||
}
|
||||
10
WeddingShare/Models/Database/UserModel.cs
Normal file
10
WeddingShare/Models/Database/UserModel.cs
Normal file
@@ -0,0 +1,10 @@
|
||||
namespace WeddingShare.Models.Database
|
||||
{
|
||||
public class UserModel
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public string? Name { get; set; }
|
||||
public string? Email { get; set; }
|
||||
public string? Password { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -4,6 +4,6 @@ namespace WeddingShare.Models
|
||||
{
|
||||
public string? RequestId { get; set; }
|
||||
|
||||
public bool ShowRequestId => !string.IsNullOrEmpty(RequestId);
|
||||
public bool ShowRequestId => !string.IsNullOrWhiteSpace(RequestId);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,14 +8,15 @@
|
||||
}
|
||||
|
||||
public PhotoGallery(int columnCount)
|
||||
: this("default", columnCount, string.Empty, new List<string>())
|
||||
: this("default", columnCount, string.Empty, string.Empty, new List<string>())
|
||||
{
|
||||
}
|
||||
|
||||
public PhotoGallery(string id, int columnCount, string path, List<string> images)
|
||||
public PhotoGallery(string id, int columnCount, string galleryPath, string thumbnailPath, List<string> images)
|
||||
{
|
||||
this.GalleryId = id;
|
||||
this.GalleryPath = path;
|
||||
this.GalleryPath = galleryPath;
|
||||
this.ThumbnailsPath = thumbnailPath;
|
||||
this.ColumnCount = columnCount;
|
||||
this.PendingCount = 0;
|
||||
this.Images = images;
|
||||
@@ -24,6 +25,7 @@
|
||||
|
||||
public string? GalleryId { get; set; }
|
||||
public string? GalleryPath { get; set; }
|
||||
public string? ThumbnailsPath { get; set; }
|
||||
public int ColumnCount { get; set; }
|
||||
public int PendingCount { get; set; }
|
||||
public int ApprovedCount
|
||||
|
||||
@@ -117,15 +117,33 @@
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<data name="Failed_Add_Gallery" xml:space="preserve">
|
||||
<value>Failed to create gallery</value>
|
||||
</data>
|
||||
<data name="Failed_Delete_Gallery" xml:space="preserve">
|
||||
<value>Failed to delete gallery</value>
|
||||
</data>
|
||||
<data name="Failed_Download_Gallery" xml:space="preserve">
|
||||
<value>Failed to download gallery</value>
|
||||
</data>
|
||||
<data name="Failed_Edit_Gallery" xml:space="preserve">
|
||||
<value>Failed to update gallery</value>
|
||||
</data>
|
||||
<data name="Failed_Finding_File" xml:space="preserve">
|
||||
<value>Failed to find file</value>
|
||||
</data>
|
||||
<data name="Failed_Reviewing_Photo" xml:space="preserve">
|
||||
<value>Failed to review photo</value>
|
||||
</data>
|
||||
<data name="Gallery_Name_Already_Exists" xml:space="preserve">
|
||||
<value>Gallery name already exists</value>
|
||||
</data>
|
||||
<data name="Login_Failed" xml:space="preserve">
|
||||
<value>Faied to log user in</value>
|
||||
</data>
|
||||
<data name="Name_Cannot_Be_Blank" xml:space="preserve">
|
||||
<value>Gallery name cannot be empty</value>
|
||||
</data>
|
||||
<data name="Pending_Uploads_Failed" xml:space="preserve">
|
||||
<value>Failed to get pending uploads</value>
|
||||
</data>
|
||||
|
||||
@@ -117,15 +117,33 @@
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<data name="Failed_Add_Gallery" xml:space="preserve">
|
||||
<value>Impossible de créer la galerie</value>
|
||||
</data>
|
||||
<data name="Failed_Delete_Gallery" xml:space="preserve">
|
||||
<value>Impossible de supprimer la galerie</value>
|
||||
</data>
|
||||
<data name="Failed_Download_Gallery" xml:space="preserve">
|
||||
<value>Impossible de télécharger la galerie</value>
|
||||
</data>
|
||||
<data name="Failed_Edit_Gallery" xml:space="preserve">
|
||||
<value>Échec de la mise à jour de la galerie</value>
|
||||
</data>
|
||||
<data name="Failed_Finding_File" xml:space="preserve">
|
||||
<value>Impossible de trouver le fichier</value>
|
||||
</data>
|
||||
<data name="Failed_Reviewing_Photo" xml:space="preserve">
|
||||
<value>Impossible de vérifier la photo</value>
|
||||
</data>
|
||||
<data name="Gallery_Name_Already_Exists" xml:space="preserve">
|
||||
<value>Le nom de la galerie existe déjà</value>
|
||||
</data>
|
||||
<data name="Login_Failed" xml:space="preserve">
|
||||
<value>Impossible de connecter l'utilisateur</value>
|
||||
</data>
|
||||
<data name="Name_Cannot_Be_Blank" xml:space="preserve">
|
||||
<value>Le nom de la galerie ne peut pas être vide</value>
|
||||
</data>
|
||||
<data name="Pending_Uploads_Failed" xml:space="preserve">
|
||||
<value>Impossible d'obtenir les téléchargements en attente</value>
|
||||
</data>
|
||||
|
||||
@@ -120,6 +120,9 @@
|
||||
<data name="File_Upload_Failed" xml:space="preserve">
|
||||
<value>Failed to upload file</value>
|
||||
</data>
|
||||
<data name="Gallery_Does_Not_Exist" xml:space="preserve">
|
||||
<value>The requested gallery was not found or does not exist</value>
|
||||
</data>
|
||||
<data name="Image_Upload_Failed" xml:space="preserve">
|
||||
<value>Failed to upload images</value>
|
||||
</data>
|
||||
@@ -135,12 +138,15 @@
|
||||
<data name="Invalid_Gallery_Key" xml:space="preserve">
|
||||
<value>Invalid gallery key</value>
|
||||
</data>
|
||||
<data name="Invalid_Security_Key_Warning" xml:space="preserve">
|
||||
<value>A request was made using an invalid security key</value>
|
||||
<data name="Invalid_Secret_Key_Warning" xml:space="preserve">
|
||||
<value>A request was made using an invalid secret key</value>
|
||||
</data>
|
||||
<data name="Max_File_Size" xml:space="preserve">
|
||||
<value>Max file size is</value>
|
||||
</data>
|
||||
<data name="No_Files_For_Upload" xml:space="preserve">
|
||||
<value>No files were detected for upload</value>
|
||||
</data>
|
||||
<data name="Save_To_Gallery_Failed" xml:space="preserve">
|
||||
<value>Failed to save image to gallery</value>
|
||||
</data>
|
||||
|
||||
@@ -120,6 +120,9 @@
|
||||
<data name="File_Upload_Failed" xml:space="preserve">
|
||||
<value>Impossible de télécharger le fichier</value>
|
||||
</data>
|
||||
<data name="Gallery_Does_Not_Exist" xml:space="preserve">
|
||||
<value>La galerie demandée n'a pas été trouvée ou n'existe pas</value>
|
||||
</data>
|
||||
<data name="Image_Upload_Failed" xml:space="preserve">
|
||||
<value>Impossible de télécharger les images</value>
|
||||
</data>
|
||||
@@ -135,12 +138,15 @@
|
||||
<data name="Invalid_Gallery_Key" xml:space="preserve">
|
||||
<value>Clé de galerie non valide</value>
|
||||
</data>
|
||||
<data name="Invalid_Security_Key_Warning" xml:space="preserve">
|
||||
<data name="Invalid_Secret_Key_Warning" xml:space="preserve">
|
||||
<value>Une demande a été effectuée à l'aide d'une clé de sécurité non valide</value>
|
||||
</data>
|
||||
<data name="Max_File_Size" xml:space="preserve">
|
||||
<value>La taille maximale du fichier est</value>
|
||||
</data>
|
||||
<data name="No_Files_For_Upload" xml:space="preserve">
|
||||
<value>Aucun fichier n'a été détecté pour le téléchargement</value>
|
||||
</data>
|
||||
<data name="Save_To_Gallery_Failed" xml:space="preserve">
|
||||
<value>Impossible d'enregistrer l'image dans la galerie</value>
|
||||
</data>
|
||||
|
||||
@@ -117,12 +117,27 @@
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<data name="Actions" xml:space="preserve">
|
||||
<value>Actions</value>
|
||||
</data>
|
||||
<data name="Approve" xml:space="preserve">
|
||||
<value>Approve</value>
|
||||
</data>
|
||||
<data name="Approved" xml:space="preserve">
|
||||
<value>Approved</value>
|
||||
</data>
|
||||
<data name="Available_Galleries" xml:space="preserve">
|
||||
<value>Available Galleries</value>
|
||||
</data>
|
||||
<data name="Create" xml:space="preserve">
|
||||
<value>Create</value>
|
||||
</data>
|
||||
<data name="Delete" xml:space="preserve">
|
||||
<value>Delete</value>
|
||||
</data>
|
||||
<data name="Key" xml:space="preserve">
|
||||
<value>Key</value>
|
||||
</data>
|
||||
<data name="Link" xml:space="preserve">
|
||||
<value>Link</value>
|
||||
</data>
|
||||
@@ -135,10 +150,19 @@
|
||||
<data name="No_Pending_Uploads" xml:space="preserve">
|
||||
<value>No uploads pending review</value>
|
||||
</data>
|
||||
<data name="Pending" xml:space="preserve">
|
||||
<value>Pending</value>
|
||||
</data>
|
||||
<data name="Pending_Uploads" xml:space="preserve">
|
||||
<value>Pending Uploads</value>
|
||||
</data>
|
||||
<data name="Reject" xml:space="preserve">
|
||||
<value>Reject</value>
|
||||
</data>
|
||||
<data name="Rename" xml:space="preserve">
|
||||
<value>Rename</value>
|
||||
</data>
|
||||
<data name="Total" xml:space="preserve">
|
||||
<value>Total</value>
|
||||
</data>
|
||||
</root>
|
||||
@@ -117,12 +117,27 @@
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<data name="Actions" xml:space="preserve">
|
||||
<value>Actes</value>
|
||||
</data>
|
||||
<data name="Approve" xml:space="preserve">
|
||||
<value>Approuver</value>
|
||||
</data>
|
||||
<data name="Approved" xml:space="preserve">
|
||||
<value>Approuvée</value>
|
||||
</data>
|
||||
<data name="Available_Galleries" xml:space="preserve">
|
||||
<value>Galeries disponibles</value>
|
||||
</data>
|
||||
<data name="Create" xml:space="preserve">
|
||||
<value>Créer</value>
|
||||
</data>
|
||||
<data name="Delete" xml:space="preserve">
|
||||
<value>Supprimer</value>
|
||||
</data>
|
||||
<data name="Key" xml:space="preserve">
|
||||
<value>Clé</value>
|
||||
</data>
|
||||
<data name="Link" xml:space="preserve">
|
||||
<value>Lien</value>
|
||||
</data>
|
||||
@@ -135,10 +150,19 @@
|
||||
<data name="No_Pending_Uploads" xml:space="preserve">
|
||||
<value>Aucun téléchargement en attente de révision</value>
|
||||
</data>
|
||||
<data name="Pending" xml:space="preserve">
|
||||
<value>En attente</value>
|
||||
</data>
|
||||
<data name="Pending_Uploads" xml:space="preserve">
|
||||
<value>Téléchargements en attente</value>
|
||||
</data>
|
||||
<data name="Reject" xml:space="preserve">
|
||||
<value>Rejeter</value>
|
||||
</data>
|
||||
<data name="Rename" xml:space="preserve">
|
||||
<value>Rebaptiser</value>
|
||||
</data>
|
||||
<data name="Total" xml:space="preserve">
|
||||
<value>Totale</value>
|
||||
</data>
|
||||
</root>
|
||||
@@ -1,126 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<!--
|
||||
Microsoft ResX Schema
|
||||
|
||||
Version 2.0
|
||||
|
||||
The primary goals of this format is to allow a simple XML format
|
||||
that is mostly human readable. The generation and parsing of the
|
||||
various data types are done through the TypeConverter classes
|
||||
associated with the data types.
|
||||
|
||||
Example:
|
||||
|
||||
... ado.net/XML headers & schema ...
|
||||
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||
<resheader name="version">2.0</resheader>
|
||||
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
||||
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||
</data>
|
||||
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||
<comment>This is a comment</comment>
|
||||
</data>
|
||||
|
||||
There are any number of "resheader" rows that contain simple
|
||||
name/value pairs.
|
||||
|
||||
Each data row contains a name, and value. The row also contains a
|
||||
type or mimetype. Type corresponds to a .NET class that support
|
||||
text/value conversion through the TypeConverter architecture.
|
||||
Classes that don't support this are serialized and stored with the
|
||||
mimetype set.
|
||||
|
||||
The mimetype is used for serialized objects, and tells the
|
||||
ResXResourceReader how to depersist the object. This is currently not
|
||||
extensible. For a given mimetype the value must be set accordingly:
|
||||
|
||||
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||
that the ResXResourceWriter will generate, however the reader can
|
||||
read any of the formats listed below.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.binary.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.soap.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||
value : The object must be serialized into a byte array
|
||||
: using a System.ComponentModel.TypeConverter
|
||||
: and then encoded with base64 encoding.
|
||||
-->
|
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
<xsd:complexType>
|
||||
<xsd:choice maxOccurs="unbounded">
|
||||
<xsd:element name="metadata">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||
<xsd:attribute name="type" type="xsd:string" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="assembly">
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="alias" type="xsd:string" />
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="data">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="resheader">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:choice>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:schema>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<data name="Access_Denied" xml:space="preserve">
|
||||
<value>Access Denied</value>
|
||||
</data>
|
||||
<data name="Access_Denied_Message" xml:space="preserve">
|
||||
<value>It looks like you are not authorized to view that page...</value>
|
||||
</data>
|
||||
</root>
|
||||
@@ -1,126 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<!--
|
||||
Microsoft ResX Schema
|
||||
|
||||
Version 2.0
|
||||
|
||||
The primary goals of this format is to allow a simple XML format
|
||||
that is mostly human readable. The generation and parsing of the
|
||||
various data types are done through the TypeConverter classes
|
||||
associated with the data types.
|
||||
|
||||
Example:
|
||||
|
||||
... ado.net/XML headers & schema ...
|
||||
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||
<resheader name="version">2.0</resheader>
|
||||
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
||||
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||
</data>
|
||||
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||
<comment>This is a comment</comment>
|
||||
</data>
|
||||
|
||||
There are any number of "resheader" rows that contain simple
|
||||
name/value pairs.
|
||||
|
||||
Each data row contains a name, and value. The row also contains a
|
||||
type or mimetype. Type corresponds to a .NET class that support
|
||||
text/value conversion through the TypeConverter architecture.
|
||||
Classes that don't support this are serialized and stored with the
|
||||
mimetype set.
|
||||
|
||||
The mimetype is used for serialized objects, and tells the
|
||||
ResXResourceReader how to depersist the object. This is currently not
|
||||
extensible. For a given mimetype the value must be set accordingly:
|
||||
|
||||
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||
that the ResXResourceWriter will generate, however the reader can
|
||||
read any of the formats listed below.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.binary.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.soap.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||
value : The object must be serialized into a byte array
|
||||
: using a System.ComponentModel.TypeConverter
|
||||
: and then encoded with base64 encoding.
|
||||
-->
|
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
<xsd:complexType>
|
||||
<xsd:choice maxOccurs="unbounded">
|
||||
<xsd:element name="metadata">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||
<xsd:attribute name="type" type="xsd:string" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="assembly">
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="alias" type="xsd:string" />
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="data">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="resheader">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:choice>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:schema>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<data name="Access_Denied" xml:space="preserve">
|
||||
<value>Accès refusé</value>
|
||||
</data>
|
||||
<data name="Access_Denied_Message" xml:space="preserve">
|
||||
<value>Il semble que vous n'êtes pas autorisé à voir cette page...</value>
|
||||
</data>
|
||||
</root>
|
||||
@@ -117,10 +117,28 @@
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<data name="Unexpected_Error" xml:space="preserve">
|
||||
<value>Opps, it looks like an unexpected error occurred...</value>
|
||||
</data>
|
||||
<data name="Unexpected_Error_Message" xml:space="preserve">
|
||||
<data name="400_Error_Message" xml:space="preserve">
|
||||
<value>If this issue persists please contact the web administrator</value>
|
||||
</data>
|
||||
<data name="400_Error_Title" xml:space="preserve">
|
||||
<value>Opps, it looks like an unexpected error occurred...</value>
|
||||
</data>
|
||||
<data name="401_Error_Message" xml:space="preserve">
|
||||
<value>It looks like you are not authorized to view that page...</value>
|
||||
</data>
|
||||
<data name="401_Error_Title" xml:space="preserve">
|
||||
<value>Access Denied</value>
|
||||
</data>
|
||||
<data name="402_Error_Message" xml:space="preserve">
|
||||
<value>The provided secret key was incorrect</value>
|
||||
</data>
|
||||
<data name="402_Error_Title" xml:space="preserve">
|
||||
<value>Invalid Secret Key</value>
|
||||
</data>
|
||||
<data name="403_Error_Message" xml:space="preserve">
|
||||
<value>The specified gellery does not exist and you do not have permissions to create it</value>
|
||||
</data>
|
||||
<data name="403_Error_Title" xml:space="preserve">
|
||||
<value>Access Denied</value>
|
||||
</data>
|
||||
</root>
|
||||
@@ -117,10 +117,28 @@
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<data name="Unexpected_Error" xml:space="preserve">
|
||||
<value>Oups, il semble qu'une erreur inattendue se soit produite...</value>
|
||||
</data>
|
||||
<data name="Unexpected_Error_Message" xml:space="preserve">
|
||||
<data name="400_Error_Message" xml:space="preserve">
|
||||
<value>Si ce problème persiste, veuillez contacter l'administrateur Web</value>
|
||||
</data>
|
||||
<data name="400_Error_Title" xml:space="preserve">
|
||||
<value>Oups, il semble qu'une erreur inattendue se soit produite...</value>
|
||||
</data>
|
||||
<data name="401_Error_Message" xml:space="preserve">
|
||||
<value>Il semble que vous n'êtes pas autorisé à voir cette page...</value>
|
||||
</data>
|
||||
<data name="401_Error_Title" xml:space="preserve">
|
||||
<value>Accès refusé</value>
|
||||
</data>
|
||||
<data name="402_Error_Message" xml:space="preserve">
|
||||
<value>La clé secrète fournie était incorrecte</value>
|
||||
</data>
|
||||
<data name="402_Error_Title" xml:space="preserve">
|
||||
<value>Clé secrète invalide</value>
|
||||
</data>
|
||||
<data name="403_Error_Message" xml:space="preserve">
|
||||
<value>La galerie spécifiée n'existe pas et vous n'avez pas les autorisations pour la créer</value>
|
||||
</data>
|
||||
<data name="403_Error_Title" xml:space="preserve">
|
||||
<value>Accès refusé</value>
|
||||
</data>
|
||||
</root>
|
||||
@@ -1,4 +1,4 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<!--
|
||||
Microsoft ResX Schema
|
||||
@@ -117,8 +117,11 @@
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<data name="Click_To_Upload" xml:space="preserve">
|
||||
<value>Click here to select files to upload</value>
|
||||
</data>
|
||||
<data name="Drag_And_Drop" xml:space="preserve">
|
||||
<value>Drag &amp; Drop image(s) here to upload them to the gallery</value>
|
||||
<value>Drag & Drop image(s) here to upload them to the gallery</value>
|
||||
</data>
|
||||
<data name="Upload_Photos" xml:space="preserve">
|
||||
<value>Upload Photos</value>
|
||||
|
||||
@@ -117,6 +117,9 @@
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<data name="Click_To_Upload" xml:space="preserve">
|
||||
<value>Cliquez ici pour sélectionner les fichiers à télécharger</value>
|
||||
</data>
|
||||
<data name="Drag_And_Drop" xml:space="preserve">
|
||||
<value>Faites glisser et déposez les images ici pour les télécharger dans la galerie</value>
|
||||
</data>
|
||||
|
||||
@@ -123,4 +123,22 @@
|
||||
<data name="Default" xml:space="preserve">
|
||||
<value>Default</value>
|
||||
</data>
|
||||
<data name="Delete_Confirmation" xml:space="preserve">
|
||||
<value>Are you sure you want to delete this gallery?</value>
|
||||
</data>
|
||||
<data name="Gallery_Key" xml:space="preserve">
|
||||
<value>Secret Key</value>
|
||||
</data>
|
||||
<data name="Gallery_Key_Help" xml:space="preserve">
|
||||
<value>Please enter a new secret key for the gallery</value>
|
||||
</data>
|
||||
<data name="Gallery_Name" xml:space="preserve">
|
||||
<value>Gallery Name</value>
|
||||
</data>
|
||||
<data name="Gallery_Name_Help" xml:space="preserve">
|
||||
<value>Please enter a new name for the gallery</value>
|
||||
</data>
|
||||
<data name="Update" xml:space="preserve">
|
||||
<value>Update</value>
|
||||
</data>
|
||||
</root>
|
||||
@@ -123,4 +123,22 @@
|
||||
<data name="Default" xml:space="preserve">
|
||||
<value>Défaut</value>
|
||||
</data>
|
||||
<data name="Delete_Confirmation" xml:space="preserve">
|
||||
<value>Etes-vous sûr de vouloir supprimer cette galerie ?</value>
|
||||
</data>
|
||||
<data name="Gallery_Key" xml:space="preserve">
|
||||
<value>Clé secrète</value>
|
||||
</data>
|
||||
<data name="Gallery_Key_Help" xml:space="preserve">
|
||||
<value>Veuillez saisir une nouvelle clé secrète pour la galerie</value>
|
||||
</data>
|
||||
<data name="Gallery_Name" xml:space="preserve">
|
||||
<value>Nom de la galerie</value>
|
||||
</data>
|
||||
<data name="Gallery_Name_Help" xml:space="preserve">
|
||||
<value>Veuillez saisir un nouveau nom pour la galerie</value>
|
||||
</data>
|
||||
<data name="Update" xml:space="preserve">
|
||||
<value>Mise à jour</value>
|
||||
</data>
|
||||
</root>
|
||||
39
WeddingShare/SqlScripts/SQLite/000 - Initialize Database.sql
Normal file
39
WeddingShare/SqlScripts/SQLite/000 - Initialize Database.sql
Normal file
@@ -0,0 +1,39 @@
|
||||
--
|
||||
-- Table structure for table `galleries`
|
||||
--
|
||||
DROP TABLE IF EXISTS `galleries`;
|
||||
CREATE TABLE `galleries` (
|
||||
`id` INTEGER NOT NULL PRIMARY KEY,
|
||||
`name` TEXT NOT NULL UNIQUE,
|
||||
`secret_key` TEXT NULL
|
||||
);
|
||||
|
||||
DROP TABLE IF EXISTS `gallery_items`;
|
||||
CREATE TABLE `gallery_items` (
|
||||
`id` INTEGER NOT NULL PRIMARY KEY,
|
||||
`gallery_id` INTEGER NOT NULL,
|
||||
`title` TEXT NOT NULL,
|
||||
`uploaded_by` TEXT NULL,
|
||||
`state` INTEGER NOT NULL DEFAULT `0`,
|
||||
FOREIGN KEY (`gallery_id`) REFERENCES `galleries` (`id`)
|
||||
);
|
||||
|
||||
INSERT INTO `galleries`
|
||||
(`id`, `name`, `secret_key`)
|
||||
VALUES
|
||||
(1, 'default', NULL);
|
||||
|
||||
--
|
||||
-- Table structure for table `users`
|
||||
--
|
||||
DROP TABLE IF EXISTS `users`;
|
||||
CREATE TABLE `users` (
|
||||
`id` INTEGER NOT NULL PRIMARY KEY,
|
||||
`username` TEXT NOT NULL UNIQUE,
|
||||
`email` TEXT NULL UNIQUE,
|
||||
`password` TEXT NOT NULL
|
||||
);
|
||||
|
||||
INSERT INTO `users`
|
||||
VALUES
|
||||
(1,'admin', NULL, 'admin');
|
||||
@@ -1,22 +1,42 @@
|
||||
using Microsoft.AspNetCore.Authentication.Cookies;
|
||||
using System.Globalization;
|
||||
using Microsoft.AspNetCore.Authentication.Cookies;
|
||||
using Microsoft.AspNetCore.Localization;
|
||||
using System.Globalization;
|
||||
using Microsoft.AspNetCore.Server.Kestrel.Core;
|
||||
using WeddingShare.Helpers;
|
||||
using WeddingShare.Helpers.Database;
|
||||
using WeddingShare.Helpers.Dbup;
|
||||
|
||||
namespace WeddingShare
|
||||
{
|
||||
public class Startup
|
||||
{
|
||||
public Startup(IConfiguration configuration)
|
||||
private readonly ILoggerFactory _loggerFactory;
|
||||
|
||||
public Startup(IConfiguration configuration, ILoggerFactory loggerFactory)
|
||||
{
|
||||
Configuration = configuration;
|
||||
_loggerFactory = loggerFactory;
|
||||
}
|
||||
|
||||
public IConfiguration Configuration { get; }
|
||||
|
||||
public void ConfigureServices(IServiceCollection services)
|
||||
{
|
||||
services.AddScoped<IConfigHelper, ConfigHelper>();
|
||||
{
|
||||
services.AddSingleton<IConfigHelper, ConfigHelper>();
|
||||
services.AddSingleton<IEnvironmentWrapper, EnvironmentWrapper>();
|
||||
services.AddSingleton<ISecretKeyHelper, SecretKeyHelper>();
|
||||
services.AddSingleton<IImageHelper, ImageHelper>();
|
||||
|
||||
var config = new ConfigHelper(new EnvironmentWrapper(), Configuration, _loggerFactory.CreateLogger<ConfigHelper>());
|
||||
switch (config.GetOrDefault("Database", "Database_Type", "sqlite")?.ToLower())
|
||||
{
|
||||
case "sqlite":
|
||||
services.AddSingleton<IDatabaseHelper, SQLiteDatabaseHelper>();
|
||||
break;
|
||||
}
|
||||
|
||||
services.AddHostedService<DbupMigrator>();
|
||||
services.AddHostedService<DirectoryScanner>();
|
||||
|
||||
services.AddRazorPages();
|
||||
services.AddControllersWithViews().AddRazorRuntimeCompilation();
|
||||
@@ -26,6 +46,11 @@ namespace WeddingShare
|
||||
options.ResourcesPath = "Resources";
|
||||
});
|
||||
|
||||
services.Configure<KestrelServerOptions>(options =>
|
||||
{
|
||||
options.Limits.MaxRequestBodySize = int.MaxValue;
|
||||
});
|
||||
|
||||
services.Configure<RequestLocalizationOptions>(options => {
|
||||
var supportedCultures = new[]
|
||||
{
|
||||
@@ -45,10 +70,9 @@ namespace WeddingShare
|
||||
options.ExpireTimeSpan = TimeSpan.FromMinutes(10);
|
||||
|
||||
options.LoginPath = "/Home";
|
||||
options.AccessDeniedPath = "/Error/AccessDenied";
|
||||
options.AccessDeniedPath = $"/Error?Reason={ErrorCode.Unauthorized}";
|
||||
options.SlidingExpiration = true;
|
||||
});
|
||||
|
||||
services.AddSession();
|
||||
}
|
||||
|
||||
@@ -60,7 +84,12 @@ namespace WeddingShare
|
||||
app.UseHsts();
|
||||
}
|
||||
|
||||
app.UseHttpsRedirection();
|
||||
var config = new ConfigHelper(new EnvironmentWrapper(), Configuration, _loggerFactory.CreateLogger<ConfigHelper>());
|
||||
if (config.GetOrDefault("Settings", "Force_Https", false))
|
||||
{
|
||||
app.UseHttpsRedirection();
|
||||
}
|
||||
|
||||
app.UseStaticFiles();
|
||||
app.UseRouting();
|
||||
app.UseAuthentication();
|
||||
|
||||
@@ -2,27 +2,59 @@
|
||||
@using WeddingShare.Views.Admin
|
||||
@inject Microsoft.Extensions.Localization.IStringLocalizer<IndexModel> _localizer
|
||||
@inject WeddingShare.Helpers.IConfigHelper _config
|
||||
@inject WeddingShare.Helpers.ISecretKeyHelper _secretKey
|
||||
|
||||
<section class="py-1 pt-lg-5">
|
||||
<div class="container px-3 px-lg-1 my-3 mt-lg-1">
|
||||
@if (Model?.Galleries != null && Model.Galleries.Any())
|
||||
{
|
||||
var key = _config.GetOrDefault("Settings", "Secret_Key", string.Empty);
|
||||
var ctx = Context.Request;
|
||||
var link = $"{ctx.Scheme}://{ctx.Host}/Gallery?{(!string.IsNullOrEmpty(key) ? $"key={key}&" : string.Empty)}";
|
||||
var link = $"{(_config.GetOrDefault("Settings", "Force_Https", false) ? "https" : ctx.Scheme)}://{ctx.Host}/Gallery";
|
||||
|
||||
<h1 class="display-6">@_localizer["Available_Galleries"].Value: </h1>
|
||||
<h1 class="display-6">
|
||||
<span class="float-none">@_localizer["Available_Galleries"].Value: </span>
|
||||
@if (!_config.GetOrDefault("Settings", "Single_Gallery_Mode", false))
|
||||
{
|
||||
<span class="float-end"><i class="btnAddGallery fa-solid fa-calendar-plus fa-2x text-success pointer px-2" alt="Create"></i></span>
|
||||
}
|
||||
</h1>
|
||||
<table class="table table-bordered">
|
||||
<tr>
|
||||
<th>@_localizer["Name"].Value</th>
|
||||
<th>@_localizer["Link"].Value</th>
|
||||
<th class="col-6 col-md-4">@_localizer["Name"].Value</th>
|
||||
<th class="col-1 d-none d-md-table-cell">@_localizer["Total"].Value</th>
|
||||
<th class="col-1 d-none d-md-table-cell">@_localizer["Approved"].Value</th>
|
||||
<th class="col-1 d-none d-md-table-cell">@_localizer["Pending"].Value</th>
|
||||
<th class="col-1 d-none d-md-table-cell">@_localizer["Key"].Value</th>
|
||||
<th class="col-6 col-md-4">@_localizer["Actions"].Value</th>
|
||||
</tr>
|
||||
@foreach (var gallery in Model.Galleries)
|
||||
@foreach (var gallery in Model.Galleries.OrderBy(x => string.Equals("default", x.Name, StringComparison.OrdinalIgnoreCase) ? 0 : 1))
|
||||
{
|
||||
var galleryLink = $"{link}id={gallery.Key}";
|
||||
<tr>
|
||||
<td class="text-capitalize">@gallery.Key</td>
|
||||
<td><a href="@galleryLink">@galleryLink</a></td>
|
||||
var secretKey = await _secretKey.GetGallerySecretKey(gallery.Name);
|
||||
var galleryLink = $"{link}?id={gallery.Name}{(!string.IsNullOrWhiteSpace(secretKey) ? $"&key={secretKey}" : string.Empty)}";
|
||||
|
||||
<tr data-gallery-id="@gallery.Id" data-gallery-name="@gallery.Name" data-gallery-key="@secretKey">
|
||||
<td class="gallery-name text-capitalize">@gallery.Name</td>
|
||||
<td class="d-none d-md-table-cell text-center">@gallery.TotalItems</td>
|
||||
<td class="d-none d-md-table-cell text-center">@gallery.ApprovedItems</td>
|
||||
<td class="d-none d-md-table-cell text-center">@gallery.PendingItems</td>
|
||||
<td class="d-none d-md-table-cell text-center">
|
||||
<i class="fa-solid @(!string.IsNullOrWhiteSpace(secretKey) ? "fa-lock" : "fa-lock-open") m-0"></i>
|
||||
</td>
|
||||
<td>
|
||||
<i class="btnOpenGallery btn btn-outline-primary fa-solid fa-up-right-from-square" data-url="@galleryLink" alt="Open"></i>
|
||||
<i class="btnDownloadGallery btn @(gallery.TotalItems > 0 ? "btn-outline-primary" : "btn-outline-disabled") fa-solid fa-download" alt="Download" @(gallery.TotalItems == 0 ? "disabled=disabled" : string.Empty)></i>
|
||||
|
||||
@if (gallery.Id > 1)
|
||||
{
|
||||
<i class="btnEditGallery btn btn-outline-success fa-solid fa-pen-to-square" alt="Rename"></i>
|
||||
<i class="btnDeleteGallery btn btn-outline-danger fa-solid fa-trash-can" alt="Delete"></i>
|
||||
}
|
||||
else
|
||||
{
|
||||
<i class="btn btn-outline-disabled fa-solid fa-pen-to-square" alt="Rename"></i>
|
||||
<i class="btn btn-outline-disabled fa-solid fa-trash-can" alt="Delete"></i>
|
||||
}
|
||||
</td>
|
||||
</tr>
|
||||
}
|
||||
</table>
|
||||
@@ -47,23 +79,20 @@
|
||||
foreach (var review in Model.PendingRequests)
|
||||
{
|
||||
<div class="col-12 mb-4 mb-lg-0 mb-1 mb-lg-5">
|
||||
@{
|
||||
var photo = review.Replace('\\', '/');
|
||||
var parts = photo.Split(new char[] { '/' }, StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries);
|
||||
|
||||
<div class="card pending-approval">
|
||||
<div class="card-header">
|
||||
<h5 class="card-title m-0 text-capitalize">@parts[0]</h5>
|
||||
</div>
|
||||
<img src="/uploads/@photo" alt="" />
|
||||
<div class="card-body m-0 p-0">
|
||||
<div class="btn-group w-100" role="group" data-gallery-id="@parts[0]" data-photo-id="@parts[2]">
|
||||
<button type="button" class="btn btn-success btnReviewApprove">@_localizer["Approve"].Value</button>
|
||||
<button type="button" class="btn btn-danger btnReviewReject">@_localizer["Reject"].Value</button>
|
||||
</div>
|
||||
<div class="card pending-approval">
|
||||
<div class="card-header">
|
||||
<h5 class="card-title m-0 text-capitalize">
|
||||
@review.Title.Split('.', StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries).FirstOrDefault()
|
||||
</h5>
|
||||
</div>
|
||||
<img src="/uploads/@review.GalleryName/Pending/@review.Title" loading="lazy" />
|
||||
<div class="card-body m-0 p-0">
|
||||
<div class="btn-group w-100" role="group" data-id="@review.Id">
|
||||
<button type="button" class="btn btn-success btnReviewApprove">@_localizer["Approve"].Value</button>
|
||||
<button type="button" class="btn btn-danger btnReviewReject">@_localizer["Reject"].Value</button>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
}
|
||||
@@ -75,4 +104,6 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
</section>
|
||||
|
||||
<script src="~/js/admin.js" asp-append-version="true"></script>
|
||||
@@ -1,4 +1,5 @@
|
||||
using Microsoft.AspNetCore.Mvc.RazorPages;
|
||||
using WeddingShare.Models.Database;
|
||||
|
||||
namespace WeddingShare.Views.Admin
|
||||
{
|
||||
@@ -8,8 +9,8 @@ namespace WeddingShare.Views.Admin
|
||||
{
|
||||
}
|
||||
|
||||
public List<KeyValuePair<string, string>>? Galleries { get; set; }
|
||||
public List<string>? PendingRequests { get; set; }
|
||||
public List<GalleryModel>? Galleries { get; set; }
|
||||
public List<PendingGalleryItemModel>? PendingRequests { get; set; }
|
||||
|
||||
public void OnGet()
|
||||
{
|
||||
|
||||
@@ -1,10 +0,0 @@
|
||||
@model IndexModel
|
||||
@using WeddingShare.Views.Error
|
||||
@inject Microsoft.Extensions.Localization.IStringLocalizer<AccessDeniedModel> _localizer
|
||||
@inject WeddingShare.Helpers.IConfigHelper _config
|
||||
|
||||
<!--( Error Message )-->
|
||||
<div class="content border p-5">
|
||||
<p class="text-center mb-2" style="font-size: 40px;">@_localizer["Access_Denied"].Value</p>
|
||||
<p class="text-center" style="font-size: 18px;">@_localizer["Access_Denied_Message"].Value</p>
|
||||
</div>
|
||||
@@ -1,11 +0,0 @@
|
||||
using Microsoft.AspNetCore.Mvc.RazorPages;
|
||||
|
||||
namespace WeddingShare.Views.Error
|
||||
{
|
||||
public class AccessDeniedModel : PageModel
|
||||
{
|
||||
public void OnGet()
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,10 +1,23 @@
|
||||
@model IndexModel
|
||||
@using WeddingShare.Helpers
|
||||
@using WeddingShare.Views.Error
|
||||
@inject Microsoft.Extensions.Localization.IStringLocalizer<IndexModel> _localizer
|
||||
@inject WeddingShare.Helpers.IConfigHelper _config
|
||||
|
||||
@{
|
||||
var reasonCode = 400;
|
||||
try
|
||||
{
|
||||
reasonCode = Context.Request.Query.ContainsKey("Reason") ? Convert.ToInt32(Context.Request.Query["Reason"]) : 400;
|
||||
}
|
||||
catch { }
|
||||
|
||||
var title = _localizer[$"{reasonCode}_Error_Title"].Value;
|
||||
var message = _localizer[$"{reasonCode}_Error_Message"].Value;
|
||||
}
|
||||
|
||||
<!--( Error Message )-->
|
||||
<div class="content border p-5">
|
||||
<p class="text-center mb-2" style="font-size: 40px;">@_localizer["Unexpected_Error"].Value</p>
|
||||
<p class="text-center" style="font-size: 18px;">@_localizer["Unexpected_Error_Message"].Value</p>
|
||||
<p class="text-center mb-2" style="font-size: 40px;">@title</p>
|
||||
<p class="text-center" style="font-size: 18px;">@message</p>
|
||||
</div>
|
||||
@@ -6,8 +6,8 @@
|
||||
|
||||
@{
|
||||
var ctx = Context.Request;
|
||||
var qrCodeLink = $"{ctx.Scheme}://{ctx.Host}{ctx.Path}";
|
||||
|
||||
var qrCodeLink = $"{(_config.GetOrDefault("Settings", "Force_Https", false) ? "https" : ctx.Scheme)}://{ctx.Host}{ctx.Path}";
|
||||
if (_config.GetOrDefault("Settings", "Hide_Key_From_QR_Code", false))
|
||||
{
|
||||
var queryString = new StringBuilder();
|
||||
@@ -68,4 +68,6 @@
|
||||
}
|
||||
<partial name="~/Views/Shared/_PhotoGallery.cshtml" model="Model" />
|
||||
</div>
|
||||
</section>
|
||||
</section>
|
||||
|
||||
<script src="~/js/gallery.js" asp-append-version="true"></script>
|
||||
@@ -18,9 +18,12 @@
|
||||
{
|
||||
<div class="input-group">
|
||||
<input type="text" id="gallery-id" class="form-control" aria-describedby="gallery-id-help" placeholder="@_localizer["Gallery_Name_Placeholder"].Value" aria-label="@_localizer["Gallery_Name"].Value" />
|
||||
<input type="button" id="btnGenerateGalleryName" class="btn btn-outline-success" value="@_localizer["Generate"].Value" />
|
||||
@if ((User?.Identity != null && User.Identity.IsAuthenticated) || !_config.GetOrDefault("Settings", "Disable_Guest_Gallery_Creation", true))
|
||||
{
|
||||
<input type="button" id="btnGenerateGalleryName" class="btn btn-outline-success" value="@_localizer["Generate"].Value" />
|
||||
}
|
||||
</div>
|
||||
<div id="gallery-id-help" class="form-text">
|
||||
<div id="gallery-id-help" class="form-text mb-4 mb-lg-5">
|
||||
@_localizer["Gallery_Name_Help"].Value
|
||||
</div>
|
||||
}
|
||||
@@ -29,15 +32,12 @@
|
||||
<input type="hidden" id="gallery-id" value="default" />
|
||||
}
|
||||
|
||||
@if (!string.IsNullOrEmpty(_config.Get("Settings", "Secret_Key")))
|
||||
{
|
||||
<input type="text" id="gallery-key" class="form-control mt-4" aria-describedby="gallery-key-help" placeholder="@_localizer["Gallery_Key_Placeholder"].Value" aria-label="@_localizer["Gallery_Key"].Value" />
|
||||
<div id="gallery-key-help" class="form-text">
|
||||
@_localizer["Gallery_Key_Help"].Value
|
||||
</div>
|
||||
}
|
||||
<input type="text" id="gallery-key" class="form-control" aria-describedby="gallery-key-help" placeholder="@_localizer["Gallery_Key_Placeholder"].Value" aria-label="@_localizer["Gallery_Key"].Value" />
|
||||
<div id="gallery-key-help" class="form-text mb-4 mb-lg-5">
|
||||
@_localizer["Gallery_Key_Help"].Value
|
||||
</div>
|
||||
|
||||
<div class="d-grid gap-2 @(!singleGalleryMode ? "mt-4 mt-lg-5" : string.Empty)">
|
||||
<div class="d-grid gap-2">
|
||||
<button id="btnVisitGallery" class="btn btn-primary" type="submit">@_localizer["Visit"].Value</button>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
@@ -13,10 +13,10 @@
|
||||
</svg>
|
||||
|
||||
<h2 class="strong my-2">@_localizer["Upload_Photos"].Value</h2>
|
||||
<p class="small my-2">@_localizer["Drag_And_Drop"].Value</p>
|
||||
<p class="small my-2">(@string.Join(", ", allowedFileTypes))</p>
|
||||
<p class="small my-2">@(ViewBag.IsMobile ?? false ? _localizer["Click_To_Upload"].Value : _localizer["Drag_And_Drop"].Value)</p>
|
||||
<p class="small my-2">(@string.Join(", ", allowedFileTypes).ToLower())</p>
|
||||
|
||||
<input data-post-gallery-id="@Model.GalleryId" data-post-url="@Model.UploadUrl" data-post-key="@(ViewBag.SecretKey ?? string.Empty)" class="position-absolute invisible" type="file" multiple accept="image/jpeg, image/png" />
|
||||
<input data-post-gallery-id="@Model.GalleryId" data-post-url="@Model.UploadUrl" data-post-key="@(ViewBag.SecretKey ?? string.Empty)" class="position-absolute invisible" type="file" multiple accept="image/*" />
|
||||
</fieldset>
|
||||
</form>
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
@inject WeddingShare.Helpers.IConfigHelper _config
|
||||
@inject WeddingShare.Helpers.IConfigHelper _config
|
||||
@{
|
||||
var title = _config.GetOrDefault("Settings", "Title", "WeddingShare");
|
||||
var logo = _config.GetOrDefault("Settings", "Logo", "/images/logo.png");
|
||||
@@ -20,6 +20,21 @@
|
||||
<link rel="stylesheet" href="~/css/site.css" asp-append-version="true" />
|
||||
<link rel="stylesheet" href="~/css/jquery.loading.css" asp-append-version="true" />
|
||||
<link rel="stylesheet" href="~/css/jquery.lightbox.min.css" asp-append-version="true" />
|
||||
<link rel="stylesheet" href="~/css/fontawesome.min.css" asp-append-version="true" />
|
||||
<link rel="stylesheet" href="~/css/fontawesome.regular.min.css" asp-append-version="true" />
|
||||
<link rel="stylesheet" href="~/css/fontawesome.solid.min.css" asp-append-version="true" />
|
||||
<link rel="stylesheet" href="~/css/fontawesome.brands.min.css" asp-append-version="true" />
|
||||
|
||||
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.2.3/dist/js/bootstrap.bundle.min.js"></script>
|
||||
<script src="~/lib/jquery/dist/jquery.min.js"></script>
|
||||
<script src="~/lib/bootstrap/dist/js/bootstrap.bundle.min.js"></script>
|
||||
<script src="~/lib/jquery-lightbox/lightbox-plus-jquery.min.js"></script>
|
||||
<script src="~/lib/jquery-loading/jquery.loading.min.js"></script>
|
||||
<script src="~/lib/jquery-qrcode/jquery.qrcode.min.js"></script>
|
||||
<script src="~/js/fontawesome.regular.min.js"></script>
|
||||
<script src="~/js/fontawesome.solid.min.js"></script>
|
||||
<script src="~/js/fontawesome.brands.min.js"></script>
|
||||
<script src="~/js/site.js" asp-append-version="true"></script>
|
||||
</head>
|
||||
<body>
|
||||
<!-- Navigation -->
|
||||
@@ -38,7 +53,7 @@
|
||||
try
|
||||
{
|
||||
var errorMessage = ViewBag.ErrorMessage;
|
||||
if (!string.IsNullOrEmpty(errorMessage))
|
||||
if (!string.IsNullOrWhiteSpace(errorMessage))
|
||||
{
|
||||
<div class="alert alert-danger d-flex align-items-center" role="alert">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" fill="currentColor" class="bi bi-exclamation-triangle-fill flex-shrink-0 me-2" viewBox="0 0 16 16" role="img" aria-label="Warning:">
|
||||
@@ -62,21 +77,18 @@
|
||||
<footer class="py-1 bg-dark">
|
||||
<div class="container">
|
||||
<p class="m-0 text-white">
|
||||
<span class="float-none">© Copyright Cirx08 @DateTime.UtcNow.Year</span>
|
||||
<span class="float-end">WeddingShare v@_config.GetOrDefault("Release", "Version", "1.0.0")</span>
|
||||
<span class="float-none">
|
||||
<a class="text-link text-light" href="https://github.com/Cirx08/WeddingShare" title="Copyright Cirx08" target="_blank"><i class="fa-brands fa-github"></i> WeddingShare v@_config.GetOrDefault("Release", "Version", "1.0.0") © Copyright Cirx08 @DateTime.UtcNow.Year</a>
|
||||
</span>
|
||||
<span class="float-end">
|
||||
<a class="text-link text-light" href="https://www.flaticon.com/free-icon/wedding-couple_703213" title="bride icons" target="_blank">Freepik - Flaticon</a>
|
||||
</span>
|
||||
</p>
|
||||
</div>
|
||||
</footer>
|
||||
|
||||
<!-- JS -->
|
||||
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.2.3/dist/js/bootstrap.bundle.min.js"></script>
|
||||
<script src="~/lib/jquery/dist/jquery.min.js"></script>
|
||||
<script src="~/lib/bootstrap/dist/js/bootstrap.bundle.min.js"></script>
|
||||
<script src="~/lib/jquery-lightbox/lightbox-plus-jquery.min.js"></script>
|
||||
<script src="~/lib/jquery-loading/jquery.loading.min.js"></script>
|
||||
<script src="~/lib/jquery-qrcode/jquery.qrcode.min.js"></script>
|
||||
<script src="~/js/template.js" asp-append-version="true"></script>
|
||||
<script src="~/js/site.js" asp-append-version="true"></script>
|
||||
@await RenderSectionAsync("Scripts", required: false)
|
||||
|
||||
</body>
|
||||
</html>
|
||||
@@ -1,7 +1,7 @@
|
||||
@using WeddingShare.Views.Shared
|
||||
@inject Microsoft.Extensions.Localization.IStringLocalizer<ModalsModel> _localizer
|
||||
|
||||
<div id="alert-message-modal" class="modal" tabindex="-1" role="dialog">
|
||||
<div id="alert-message-modal" class="modal pt-lg-4" tabindex="-1" role="dialog">
|
||||
<div class="modal-dialog" role="document">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
@@ -14,4 +14,119 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="add-gallery-modal" class="modal pt-lg-4" tabindex="-1" role="dialog">
|
||||
<div class="modal-dialog" role="document">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<h5 class="modal-title">@_localizer["Create"].Value</h5>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<div class="row pb-4">
|
||||
<div class="col-12">
|
||||
<label for="gallery-name">@_localizer["Gallery_Name"].Value</label>
|
||||
<input type="text" id="gallery-name" class="form-control" aria-describedby="gallery-name-help" placeholder="" aria-label="@_localizer["Gallery_Name"].Value" />
|
||||
<div id="gallery-key-help" class="form-text">
|
||||
@_localizer["Gallery_Name_Help"].Value
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row pb-4">
|
||||
<div class="col-12">
|
||||
<label for="gallery-name">@_localizer["Gallery_Key"].Value</label>
|
||||
<input type="text" id="gallery-key" class="form-control" aria-describedby="gallery-key-help" placeholder="" aria-label="@_localizer["Gallery_Key"].Value" />
|
||||
<div id="gallery-key-help" class="form-text">
|
||||
@_localizer["Gallery_Key_Help"].Value
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row pt-3">
|
||||
<div class="col-6">
|
||||
<button type="button" class="btn btn-success col-12 btnCreate" data-dismiss="modal">@_localizer["Create"].Value</button>
|
||||
</div>
|
||||
<div class="col-6">
|
||||
<button type="button" class="btn btn-secondary col-12 btnDismissPopup" data-dismiss="modal">@_localizer["Cancel"].Value</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="edit-gallery-modal" class="modal pt-lg-4" tabindex="-1" role="dialog">
|
||||
<div class="modal-dialog" role="document">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<h5 class="modal-title">@_localizer["Update"].Value</h5>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<input type="hidden" id="gallery-id" />
|
||||
|
||||
<div class="row pb-4">
|
||||
<div class="col-12">
|
||||
<label for="gallery-name">@_localizer["Gallery_Name"].Value</label>
|
||||
<input type="text" id="gallery-name" class="form-control" aria-describedby="gallery-name-help" placeholder="" aria-label="@_localizer["Gallery_Name"].Value" />
|
||||
<div id="gallery-key-help" class="form-text">
|
||||
@_localizer["Gallery_Name_Help"].Value
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row pb-4">
|
||||
<div class="col-12">
|
||||
<label for="gallery-name">@_localizer["Gallery_Key"].Value</label>
|
||||
<input type="text" id="gallery-key" class="form-control" aria-describedby="gallery-key-help" placeholder="" aria-label="@_localizer["Gallery_Key"].Value" />
|
||||
<div id="gallery-key-help" class="form-text">
|
||||
@_localizer["Gallery_Key_Help"].Value
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row pt-3">
|
||||
<div class="col-6">
|
||||
<button type="button" class="btn btn-success col-12 btnUpdate" data-dismiss="modal">@_localizer["Update"].Value</button>
|
||||
</div>
|
||||
<div class="col-6">
|
||||
<button type="button" class="btn btn-secondary col-12 btnDismissPopup" data-dismiss="modal">@_localizer["Cancel"].Value</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="delete-gallery-modal" class="modal pt-lg-4" tabindex="-1" role="dialog">
|
||||
<div class="modal-dialog" role="document">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<h5 class="modal-title">@_localizer["Delete"].Value</h5>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<input type="hidden" id="gallery-id" />
|
||||
|
||||
<div class="row pb-4">
|
||||
<div class="col-12">
|
||||
<label for="gallery-name">@_localizer["Gallery_Name"].Value</label>
|
||||
<input type="text" id="gallery-name" class="form-control" aria-describedby="gallery-name-help" placeholder="" aria-label="@_localizer["Gallery_Name"].Value" disabled="disabled" />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row pb-4">
|
||||
<div class="col-12">@_localizer["Delete_Confirmation"].Value</div>
|
||||
</div>
|
||||
|
||||
<div class="row pt-3">
|
||||
<div class="col-6">
|
||||
<button type="button" class="btn btn-danger col-12 btnDelete" data-dismiss="modal">@_localizer["Delete"].Value</button>
|
||||
</div>
|
||||
<div class="col-6">
|
||||
<button type="button" class="btn btn-secondary col-12 btnDismissPopup" data-dismiss="modal">@_localizer["Cancel"].Value</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -1,12 +1,25 @@
|
||||
@using WeddingShare.Views.Shared
|
||||
@inject WeddingShare.Helpers.IConfigHelper _config
|
||||
@inject Microsoft.Extensions.Localization.IStringLocalizer<PhotoGalleryModel> _localizer
|
||||
@model WeddingShare.Models.PhotoGallery
|
||||
@{
|
||||
var columnCount = Model.ColumnCount;
|
||||
while (12 % columnCount != 0)
|
||||
|
||||
try
|
||||
{
|
||||
columnCount--;
|
||||
if (ViewBag.IsMobile ?? false)
|
||||
{
|
||||
columnCount = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
while (12 % columnCount != 0)
|
||||
{
|
||||
columnCount--;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch { }
|
||||
}
|
||||
|
||||
@if (Model.Images != null && Model.Images.Any())
|
||||
@@ -15,13 +28,13 @@
|
||||
<div class="row">
|
||||
@for (var columnIndex = 0; columnIndex < columnCount; columnIndex++)
|
||||
{
|
||||
<div class="@($"col-lg-{12 / columnCount}") col-md-6 col-sm-12 mb-4 mb-lg-0">
|
||||
<div class="@(ViewBag.IsMobile ? "col-12" : $"col-lg-{12 / columnCount} col-md-6 col-sm-12 mb-4 mb-lg-0")">
|
||||
@{
|
||||
var index = columnIndex;
|
||||
while (index < Model.Images.Count())
|
||||
{
|
||||
<a href="@Model.GalleryPath/@Model.Images[index]" data-lightbox="@Model.GalleryId">
|
||||
<img src="@Model.GalleryPath/@Model.Images[index]" class="w-100 shadow-1-strong rounded mb-4" alt="" />
|
||||
<img src="@Model.ThumbnailsPath/@(System.IO.Path.GetFileNameWithoutExtension(Model.Images[index].TrimStart('/'))).webp" class="w-100 shadow-1-strong rounded mb-4" loading="lazy" />
|
||||
</a>
|
||||
index += columnCount;
|
||||
}
|
||||
@@ -38,4 +51,28 @@ else
|
||||
<h3 class="display-6">@_localizer["Gallery_Empty"].Value</h3>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
|
||||
@{
|
||||
var idleTimeout = _config.GetOrDefault("Settings", "Idle_Gallery_Refresh_Mins", 0);
|
||||
if (idleTimeout > 0)
|
||||
{
|
||||
<script>
|
||||
document.addEventListener('DOMContentLoaded', function () {
|
||||
$(function () {
|
||||
var idleTimeout;
|
||||
|
||||
onIdle();
|
||||
$(document).on('mousemove keydown scroll click', onIdle);
|
||||
|
||||
function onIdle() {
|
||||
clearTimeout(idleTimeout);
|
||||
idleTimeout = setTimeout(function () {
|
||||
window.location.reload();
|
||||
}, @TimeSpan.FromMinutes(idleTimeout).TotalMilliseconds);
|
||||
}
|
||||
});
|
||||
}, false);
|
||||
</script>
|
||||
}
|
||||
}
|
||||
@@ -9,15 +9,27 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Remove="SqlScripts\000 - Initialize Database.sql" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<EmbeddedResource Include="SqlScripts\SQLite\000 - Initialize Database.sql" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="dbup-sqlite" Version="5.0.40" />
|
||||
<PackageReference Include="DeviceDetector.NET" Version="6.4.1" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore" Version="8.0.1" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="8.0.1" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Identity.UI" Version="8.0.1" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation" Version="8.0.11" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.1" />
|
||||
<PackageReference Include="Microsoft.Data.Sqlite" Version="9.0.0" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="8.0.1" />
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="8.0.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="8.0.1" />
|
||||
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.19.5" />
|
||||
<PackageReference Include="NCrontab" Version="3.3.3" />
|
||||
<PackageReference Include="SixLabors.ImageSharp" Version="3.1.6" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
@@ -28,6 +40,7 @@
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Folder Include="config\" />
|
||||
<Folder Include="wwwroot\lib\jquery-qrcode\" />
|
||||
</ItemGroup>
|
||||
|
||||
|
||||
@@ -21,10 +21,20 @@
|
||||
"Disable_Upload": false,
|
||||
"Disable_Review_Counter": false,
|
||||
"Disable_QR_Code": false,
|
||||
"Hide_Key_From_QR_Code": false
|
||||
"Disable_Guest_Gallery_Creation": true,
|
||||
"Hide_Key_From_QR_Code": false,
|
||||
"Idle_Gallery_Refresh_Mins": 5,
|
||||
"Force_Https": false
|
||||
},
|
||||
"Database": {
|
||||
"Database_Type": "sqlite",
|
||||
"Connection_String": "Data Source=./config/wedding-share.db"
|
||||
},
|
||||
"BackgroundServices": {
|
||||
"Directory_Scanner_Interval": "*/30 * * * *"
|
||||
},
|
||||
"Release": {
|
||||
"Version": "1.0.4"
|
||||
"Version": "1.1.0"
|
||||
},
|
||||
"AllowedHosts": "*"
|
||||
}
|
||||
6
WeddingShare/wwwroot/css/fontawesome.brands.min.css
vendored
Normal file
6
WeddingShare/wwwroot/css/fontawesome.brands.min.css
vendored
Normal file
File diff suppressed because one or more lines are too long
9
WeddingShare/wwwroot/css/fontawesome.min.css
vendored
Normal file
9
WeddingShare/wwwroot/css/fontawesome.min.css
vendored
Normal file
File diff suppressed because one or more lines are too long
6
WeddingShare/wwwroot/css/fontawesome.regular.min.css
vendored
Normal file
6
WeddingShare/wwwroot/css/fontawesome.regular.min.css
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
/*!
|
||||
* Font Awesome Free 6.7.1 by @fontawesome - https://fontawesome.com
|
||||
* License - https://fontawesome.com/license/free (Icons: CC BY 4.0, Fonts: SIL OFL 1.1, Code: MIT License)
|
||||
* Copyright 2024 Fonticons, Inc.
|
||||
*/
|
||||
:host,:root{--fa-style-family-classic:"Font Awesome 6 Free";--fa-font-regular:normal 400 1em/1 "Font Awesome 6 Free"}@font-face{font-family:"Font Awesome 6 Free";font-style:normal;font-weight:400;font-display:block;src:url(../webfonts/fa-regular-400.woff2) format("woff2"),url(../webfonts/fa-regular-400.ttf) format("truetype")}.fa-regular,.far{font-weight:400}
|
||||
6
WeddingShare/wwwroot/css/fontawesome.solid.min.css
vendored
Normal file
6
WeddingShare/wwwroot/css/fontawesome.solid.min.css
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
/*!
|
||||
* Font Awesome Free 6.7.1 by @fontawesome - https://fontawesome.com
|
||||
* License - https://fontawesome.com/license/free (Icons: CC BY 4.0, Fonts: SIL OFL 1.1, Code: MIT License)
|
||||
* Copyright 2024 Fonticons, Inc.
|
||||
*/
|
||||
:host,:root{--fa-style-family-classic:"Font Awesome 6 Free";--fa-font-solid:normal 900 1em/1 "Font Awesome 6 Free"}@font-face{font-family:"Font Awesome 6 Free";font-style:normal;font-weight:900;font-display:block;src:url(../webfonts/fa-solid-900.woff2) format("woff2"),url(../webfonts/fa-solid-900.ttf) format("truetype")}.fa-solid,.fas{font-weight:900}
|
||||
@@ -7,6 +7,38 @@
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.pointer {
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.text-link, .text-link:hover, .text-link:active {
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
.display-6 .fa-solid {
|
||||
font-size: 25px !important;
|
||||
margin: 0px;
|
||||
}
|
||||
|
||||
.btn-outline-disabled, .btn-outline-disabled:active, .btn-outline-disabled:hover {
|
||||
color: #777777;
|
||||
border: 1px solid #777777;
|
||||
cursor: default;
|
||||
}
|
||||
|
||||
tr td {
|
||||
line-height: 30px;
|
||||
margin: 0px;
|
||||
padding: 0px;
|
||||
}
|
||||
|
||||
tr td i {
|
||||
width: 30px;
|
||||
height: 30px;
|
||||
margin: 0px 2px 0px 0px;
|
||||
padding: 5px !important;
|
||||
}
|
||||
|
||||
/* File Upload */
|
||||
.upload_drop {
|
||||
color: #FFFFFF;
|
||||
|
||||
235
WeddingShare/wwwroot/js/admin.js
Normal file
235
WeddingShare/wwwroot/js/admin.js
Normal file
@@ -0,0 +1,235 @@
|
||||
function reviewPhoto(element, action) {
|
||||
var id = element.parent('.btn-group').data('id');
|
||||
if (!id) {
|
||||
displayMessage(`Review`, `Could not find item Id`);
|
||||
return;
|
||||
}
|
||||
|
||||
displayLoader('Loading...');
|
||||
|
||||
$.ajax({
|
||||
url: '/Admin/ReviewPhoto',
|
||||
method: 'POST',
|
||||
data: { id, action }
|
||||
})
|
||||
.done(data => {
|
||||
hideLoader();
|
||||
|
||||
if (data.success === true) {
|
||||
element.closest('.pending-approval').remove();
|
||||
|
||||
if ($('.pending-approval').length == 0) {
|
||||
$('#gallery-review').addClass('visually-hidden');
|
||||
$('#no-review-msg').removeClass('visually-hidden');
|
||||
} else {
|
||||
$('#no-review-msg').addClass('visually-hidden');
|
||||
$('#gallery-review').removeClass('visually-hidden');
|
||||
}
|
||||
} else if (data.message) {
|
||||
displayMessage(`Review`, `Review failed`, [data.message]);
|
||||
}
|
||||
})
|
||||
.fail((xhr, error) => {
|
||||
hideLoader();
|
||||
displayMessage(`Review`, `Review failed`, [error]);
|
||||
});
|
||||
}
|
||||
|
||||
(function () {
|
||||
document.addEventListener('DOMContentLoaded', function () {
|
||||
|
||||
$(document).off('click', 'button.btnReviewApprove').on('click', 'button.btnReviewApprove', function (e) {
|
||||
preventDefaults(e);
|
||||
reviewPhoto($(this), 1);
|
||||
});
|
||||
|
||||
$(document).off('click', 'button.btnReviewReject').on('click', 'button.btnReviewReject', function (e) {
|
||||
preventDefaults(e);
|
||||
reviewPhoto($(this), 2);
|
||||
});
|
||||
|
||||
$(document).off('click', 'i.btnAddGallery').on('click', 'i.btnAddGallery', function (e) {
|
||||
preventDefaults(e);
|
||||
|
||||
displayPopup('add-gallery-modal');
|
||||
});
|
||||
|
||||
$(document).off('click', 'i.btnOpenGallery').on('click', 'i.btnOpenGallery', function (e) {
|
||||
preventDefaults(e);
|
||||
window.open($(this).data('url'), '_blank');
|
||||
});
|
||||
|
||||
$(document).off('click', 'i.btnDownloadGallery').on('click', 'i.btnDownloadGallery', function (e) {
|
||||
preventDefaults(e);
|
||||
|
||||
if ($(this).attr('disabled') == 'disabled') {
|
||||
return;
|
||||
}
|
||||
|
||||
displayLoader('Loading...');
|
||||
|
||||
let row = $(this).closest('tr');
|
||||
let id = row.data('gallery-id');
|
||||
|
||||
$.ajax({
|
||||
url: '/Admin/DownloadGallery',
|
||||
method: 'POST',
|
||||
data: { Id: id }
|
||||
})
|
||||
.done(data => {
|
||||
hideLoader();
|
||||
|
||||
if (data.success === true) {
|
||||
var s = window.atob(data.content);
|
||||
var bytes = new Uint8Array(s.length);
|
||||
for (var i = 0; i < s.length; i++) {
|
||||
bytes[i] = s.charCodeAt(i);
|
||||
}
|
||||
|
||||
var blob = new Blob([bytes], { type: "application/octetstream" });
|
||||
|
||||
var isIE = false || !!document.documentMode;
|
||||
if (isIE) {
|
||||
window.navigator.msSaveBlob(blob, data.filename);
|
||||
} else {
|
||||
var url = window.URL || window.webkitURL;
|
||||
link = url.createObjectURL(blob);
|
||||
var a = $("<a />");
|
||||
a.attr("download", data.filename);
|
||||
a.attr("href", link);
|
||||
$("body").append(a);
|
||||
a[0].click();
|
||||
$("body").remove(a);
|
||||
}
|
||||
} else if (data.message) {
|
||||
displayMessage(`Download`, `Download failed`, [data.message]);
|
||||
} else {
|
||||
displayMessage(`Download`, `Failed to download gallery`);
|
||||
}
|
||||
})
|
||||
.fail((xhr, error) => {
|
||||
hideLoader();
|
||||
displayMessage(`Download`, `Download failed`, [error]);
|
||||
});
|
||||
});
|
||||
|
||||
$(document).off('click', 'i.btnEditGallery').on('click', 'i.btnEditGallery', function (e) {
|
||||
preventDefaults(e);
|
||||
|
||||
let row = $(this).closest('tr');
|
||||
|
||||
$('#edit-gallery-modal #gallery-id').val(row.data('gallery-id'));
|
||||
$('#edit-gallery-modal #gallery-name').val(row.data('gallery-name'));
|
||||
$('#edit-gallery-modal #gallery-key').val(row.data('gallery-key'));
|
||||
|
||||
displayPopup('edit-gallery-modal');
|
||||
});
|
||||
|
||||
$(document).off('click', 'i.btnDeleteGallery').on('click', 'i.btnDeleteGallery', function (e) {
|
||||
preventDefaults(e);
|
||||
|
||||
let row = $(this).closest('tr');
|
||||
|
||||
$('#delete-gallery-modal #gallery-id').val(row.data('gallery-id'));
|
||||
$('#delete-gallery-modal #gallery-name').val(row.data('gallery-name'));
|
||||
|
||||
displayPopup('delete-gallery-modal');
|
||||
});
|
||||
|
||||
$(document).off('click', '#add-gallery-modal .btnCreate').on('click', '#add-gallery-modal .btnCreate', function (e) {
|
||||
preventDefaults(e);
|
||||
|
||||
hidePopup('add-gallery-modal');
|
||||
displayLoader('Loading...');
|
||||
|
||||
let name = $('#add-gallery-modal #gallery-name').val();
|
||||
let key = $('#add-gallery-modal #gallery-key').val();
|
||||
|
||||
$.ajax({
|
||||
url: '/Admin/AddGallery',
|
||||
method: 'POST',
|
||||
data: { Id: 0, Name: name, SecretKey: key }
|
||||
})
|
||||
.done(data => {
|
||||
hideLoader();
|
||||
|
||||
if (data.success === true) {
|
||||
displayMessage(`Create`, `Successfully created gallery`);
|
||||
} else if (data.message) {
|
||||
displayMessage(`Create`, `Create failed`, [data.message]);
|
||||
} else {
|
||||
displayMessage(`Create`, `Failed to create gallery`);
|
||||
}
|
||||
})
|
||||
.fail((xhr, error) => {
|
||||
hideLoader();
|
||||
displayMessage(`Create`, `Create failed`, [error]);
|
||||
});
|
||||
});
|
||||
|
||||
$(document).off('click', '#edit-gallery-modal .btnUpdate').on('click', '#edit-gallery-modal .btnUpdate', function (e) {
|
||||
preventDefaults(e);
|
||||
|
||||
hidePopup('edit-gallery-modal');
|
||||
displayLoader('Loading...');
|
||||
|
||||
let id = $('#edit-gallery-modal #gallery-id').val();
|
||||
let name = $('#edit-gallery-modal #gallery-name').val();
|
||||
let key = $('#edit-gallery-modal #gallery-key').val();
|
||||
|
||||
$.ajax({
|
||||
url: '/Admin/EditGallery',
|
||||
method: 'PUT',
|
||||
data: { Id: id, Name: name, SecretKey: key }
|
||||
})
|
||||
.done(data => {
|
||||
hideLoader();
|
||||
|
||||
if (data.success === true) {
|
||||
$(`tr[data-gallery-id=${id}] .gallery-name`).text(name);
|
||||
displayMessage(`Update`, `Successfully updated gallery`);
|
||||
} else if (data.message) {
|
||||
displayMessage(`Update`, `Update failed`, [data.message]);
|
||||
} else {
|
||||
displayMessage(`Update`, `Failed to update gallery`);
|
||||
}
|
||||
})
|
||||
.fail((xhr, error) => {
|
||||
hideLoader();
|
||||
displayMessage(`Update`, `Update failed`, [error]);
|
||||
});
|
||||
});
|
||||
|
||||
$(document).off('click', '#delete-gallery-modal .btnDelete').on('click', '#delete-gallery-modal .btnDelete', function (e) {
|
||||
preventDefaults(e);
|
||||
|
||||
hidePopup('delete-gallery-modal');
|
||||
displayLoader('Loading...');
|
||||
|
||||
let id = $('#delete-gallery-modal #gallery-id').val();
|
||||
|
||||
$.ajax({
|
||||
url: '/Admin/DeleteGallery',
|
||||
method: 'DELETE',
|
||||
data: { id }
|
||||
})
|
||||
.done(data => {
|
||||
hideLoader();
|
||||
|
||||
if (data.success === true) {
|
||||
$(`tr[data-gallery-id=${id}]`).remove();
|
||||
displayMessage(`Delete`, `Successfully deleted gallery`);
|
||||
} else if (data.message) {
|
||||
displayMessage(`Delete`, `Delete failed`, [data.message]);
|
||||
} else {
|
||||
displayMessage(`Delete`, `Failed to delete gallery`);
|
||||
}
|
||||
})
|
||||
.fail((xhr, error) => {
|
||||
hideLoader();
|
||||
displayMessage(`Delete`, `Delete failed`, [error]);
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
})();
|
||||
6
WeddingShare/wwwroot/js/fontawesome.brands.min.js
vendored
Normal file
6
WeddingShare/wwwroot/js/fontawesome.brands.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
6
WeddingShare/wwwroot/js/fontawesome.regular.min.js
vendored
Normal file
6
WeddingShare/wwwroot/js/fontawesome.regular.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
6
WeddingShare/wwwroot/js/fontawesome.solid.min.js
vendored
Normal file
6
WeddingShare/wwwroot/js/fontawesome.solid.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
152
WeddingShare/wwwroot/js/gallery.js
Normal file
152
WeddingShare/wwwroot/js/gallery.js
Normal file
@@ -0,0 +1,152 @@
|
||||
(function () {
|
||||
document.addEventListener('DOMContentLoaded', function () {
|
||||
|
||||
const triggerSelector = event => {
|
||||
const zone = event.target.closest('.upload_drop') || false;
|
||||
const input = zone.querySelector('input[type="file"]') || false;
|
||||
input.click();
|
||||
}
|
||||
|
||||
const highlight = event =>
|
||||
event.target.classList.add('highlight');
|
||||
|
||||
const unhighlight = event =>
|
||||
event.target.classList.remove('highlight');
|
||||
|
||||
const getInputAndGalleryRefs = element => {
|
||||
const zone = element.closest('.upload_drop') || false;
|
||||
const gallery = zone.querySelector('.upload_gallery') || false;
|
||||
const input = zone.querySelector('input[type="file"]') || false;
|
||||
return { input: input, gallery: gallery };
|
||||
}
|
||||
|
||||
const handleDrop = event => {
|
||||
const dataRefs = getInputAndGalleryRefs(event.target);
|
||||
dataRefs.files = event.dataTransfer.files;
|
||||
handleFiles(dataRefs);
|
||||
}
|
||||
|
||||
const eventHandlers = zone => {
|
||||
|
||||
const dataRefs = getInputAndGalleryRefs(zone);
|
||||
|
||||
if (!dataRefs.input) return;
|
||||
|
||||
// Prevent default drag behaviors
|
||||
;['dragenter', 'dragover', 'dragleave', 'drop'].forEach(event => {
|
||||
zone.addEventListener(event, preventDefaults, false);
|
||||
document.body.addEventListener(event, preventDefaults, false);
|
||||
});
|
||||
|
||||
// Open file browser on drop area click
|
||||
;['click', 'touch'].forEach(event => {
|
||||
zone.addEventListener(event, triggerSelector, false);
|
||||
});
|
||||
// Highlighting drop area when item is dragged over it
|
||||
;['dragenter', 'dragover'].forEach(event => {
|
||||
zone.addEventListener(event, highlight, false);
|
||||
});
|
||||
;['dragleave', 'drop'].forEach(event => {
|
||||
zone.addEventListener(event, unhighlight, false);
|
||||
});
|
||||
|
||||
// Handle dropped files
|
||||
zone.addEventListener('drop', handleDrop, false);
|
||||
|
||||
// Handle browse selected files
|
||||
dataRefs.input.addEventListener('change', event => {
|
||||
dataRefs.files = event.target.files;
|
||||
handleFiles(dataRefs);
|
||||
}, false);
|
||||
|
||||
}
|
||||
|
||||
// Initialise ALL dropzones
|
||||
const dropZones = document.querySelectorAll('.upload_drop');
|
||||
for (const zone of dropZones) {
|
||||
eventHandlers(zone);
|
||||
}
|
||||
|
||||
// No 'image/gif' or PDF or webp allowed here, but it's up to your use case.
|
||||
// Double checks the input "accept" attribute
|
||||
const isImageFile = file => file.type.toLowerCase().startsWith('image/');
|
||||
|
||||
// Based on: https://flaviocopes.com/how-to-upload-files-fetch/
|
||||
const imageUpload = dataRefs => {
|
||||
|
||||
// Multiple source routes, so double check validity
|
||||
if (!dataRefs.files || !dataRefs.input) {
|
||||
displayMessage(`Upload`, `No files were detected to upload`);
|
||||
return;
|
||||
}
|
||||
|
||||
const galleryId = dataRefs.input.getAttribute('data-post-gallery-id');
|
||||
if (!galleryId) {
|
||||
displayMessage(`Upload`, `Invalid gallery Id detected`);
|
||||
return;
|
||||
}
|
||||
|
||||
const url = dataRefs.input.getAttribute('data-post-url');
|
||||
if (!url) {
|
||||
displayMessage(`Upload`, `Could not find upload Url`);
|
||||
return;
|
||||
}
|
||||
|
||||
const secretKey = dataRefs.input.getAttribute('data-post-key');
|
||||
|
||||
const formData = new FormData();
|
||||
formData.append('Id', galleryId);
|
||||
formData.append('SecretKey', secretKey);
|
||||
for (var i = 0; i < dataRefs.files.length; i++) {
|
||||
formData.append(dataRefs.files[i].name, dataRefs.files[i]);
|
||||
}
|
||||
|
||||
displayLoader('Uploading...');
|
||||
|
||||
fetch(url, {
|
||||
method: 'POST',
|
||||
body: formData
|
||||
})
|
||||
.then(response => response.json())
|
||||
.then(data => {
|
||||
hideLoader();
|
||||
|
||||
if (data.success === true) {
|
||||
if (data.requiresReview === true) {
|
||||
displayMessage(`Upload`, `Successfully uploaded ${data.uploaded} photo(s) pending review`, data.errors);
|
||||
} else {
|
||||
displayMessage(`Upload`, `Successfully uploaded ${data.uploaded} photo(s)`, data.errors);
|
||||
}
|
||||
} else if (data.message) {
|
||||
displayMessage(`Upload`, `Upload failed`, [data.message]);
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
hideLoader();
|
||||
displayMessage(`Upload`, `Upload failed`, [error]);
|
||||
});
|
||||
}
|
||||
|
||||
// Handle both selected and dropped files
|
||||
const handleFiles = dataRefs => {
|
||||
|
||||
let files = [...dataRefs.files];
|
||||
|
||||
// Remove unaccepted file types
|
||||
files = files.filter(item => {
|
||||
var isImage = isImageFile(item);
|
||||
if (!isImage) {
|
||||
console.log('Not an image, ', item.type);
|
||||
}
|
||||
|
||||
return isImage ? item : null;
|
||||
});
|
||||
|
||||
if (!files.length) return;
|
||||
dataRefs.files = files;
|
||||
|
||||
imageUpload(dataRefs);
|
||||
}
|
||||
|
||||
});
|
||||
})();
|
||||
@@ -1,318 +1,133 @@
|
||||
/* Bootstrap 5 JS included */
|
||||
const preventDefaults = event => {
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
};
|
||||
|
||||
('use strict');
|
||||
function displayLoader(message) {
|
||||
$('body').loading({
|
||||
theme: 'dark',
|
||||
message,
|
||||
stoppable: false,
|
||||
start: true
|
||||
});
|
||||
}
|
||||
|
||||
function hideLoader() {
|
||||
$('body').loading('stop');
|
||||
}
|
||||
|
||||
function displayPopup(id) {
|
||||
$('body').loading({
|
||||
theme: 'dark',
|
||||
message: '',
|
||||
stoppable: false,
|
||||
start: true
|
||||
});
|
||||
$(`#${id}`).show();
|
||||
}
|
||||
|
||||
function hidePopup(id) {
|
||||
$('body').loading('stop');
|
||||
$(`#${id}`).hide();
|
||||
}
|
||||
|
||||
function uuidv4() {
|
||||
return "10000000-1000-4000-8000-100000000000".replace(/[018]/g, c =>
|
||||
(+c ^ crypto.getRandomValues(new Uint8Array(1))[0] & 15 >> +c / 4).toString(16)
|
||||
);
|
||||
}
|
||||
|
||||
function displayMessage(title, message, errors) {
|
||||
$('#alert-message-modal .modal-title').text(title);
|
||||
$('#alert-message-modal .modal-message').html(message);
|
||||
|
||||
$('#alert-message-modal .modal-error').hide();
|
||||
if (errors && errors.length > 0) {
|
||||
var errorMessage = `<b>Errors:</b>`;
|
||||
errorMessage += `<ul>`;
|
||||
errors.forEach((error) => {
|
||||
errorMessage += `<li>${error}</li>`;
|
||||
});
|
||||
errorMessage += `</ul>`;
|
||||
$('#alert-message-modal .modal-error').html(errorMessage);
|
||||
$('#alert-message-modal .modal-error').show();
|
||||
} else {
|
||||
$('#alert-message-modal .modal-error').html('');
|
||||
}
|
||||
|
||||
$('#alert-message-modal').modal('show');
|
||||
}
|
||||
|
||||
lightbox.option({
|
||||
'disableScrolling': true
|
||||
});
|
||||
|
||||
// Drag and drop - single or multiple image files
|
||||
// https://www.smashingmagazine.com/2018/01/drag-drop-file-uploader-vanilla-js/
|
||||
// https://codepen.io/joezimjs/pen/yPWQbd?editors=1000
|
||||
(function () {
|
||||
document.addEventListener('DOMContentLoaded', function () {
|
||||
|
||||
'use strict';
|
||||
|
||||
// Four objects of interest: drop zones, input elements, gallery elements, and the files.
|
||||
// dataRefs = {files: [image files], input: element ref, gallery: element ref}
|
||||
|
||||
const preventDefaults = event => {
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
};
|
||||
|
||||
const triggerSelector = event => {
|
||||
const zone = event.target.closest('.upload_drop') || false;
|
||||
const input = zone.querySelector('input[type="file"]') || false;
|
||||
input.click();
|
||||
}
|
||||
|
||||
const highlight = event =>
|
||||
event.target.classList.add('highlight');
|
||||
|
||||
const unhighlight = event =>
|
||||
event.target.classList.remove('highlight');
|
||||
|
||||
const getInputAndGalleryRefs = element => {
|
||||
const zone = element.closest('.upload_drop') || false;
|
||||
const gallery = zone.querySelector('.upload_gallery') || false;
|
||||
const input = zone.querySelector('input[type="file"]') || false;
|
||||
return { input: input, gallery: gallery };
|
||||
}
|
||||
|
||||
const handleDrop = event => {
|
||||
const dataRefs = getInputAndGalleryRefs(event.target);
|
||||
dataRefs.files = event.dataTransfer.files;
|
||||
handleFiles(dataRefs);
|
||||
}
|
||||
|
||||
const eventHandlers = zone => {
|
||||
|
||||
const dataRefs = getInputAndGalleryRefs(zone);
|
||||
|
||||
if (!dataRefs.input) return;
|
||||
|
||||
// Prevent default drag behaviors
|
||||
;['dragenter', 'dragover', 'dragleave', 'drop'].forEach(event => {
|
||||
zone.addEventListener(event, preventDefaults, false);
|
||||
document.body.addEventListener(event, preventDefaults, false);
|
||||
$(document).off('click', '.btn-reload').on('click', '.btn-reload', function () {
|
||||
window.location.reload();
|
||||
});
|
||||
|
||||
// Open file browser on drop area click
|
||||
;['click', 'touch'].forEach(event => {
|
||||
zone.addEventListener(event, triggerSelector, false);
|
||||
});
|
||||
// Highlighting drop area when item is dragged over it
|
||||
;['dragenter', 'dragover'].forEach(event => {
|
||||
zone.addEventListener(event, highlight, false);
|
||||
});
|
||||
;['dragleave', 'drop'].forEach(event => {
|
||||
zone.addEventListener(event, unhighlight, false);
|
||||
$(document).off('click', '#btnGenerateGalleryName').on('click', '#btnGenerateGalleryName', function (e) {
|
||||
preventDefaults(e);
|
||||
$('input#gallery-id').val(uuidv4());
|
||||
});
|
||||
|
||||
// Handle dropped files
|
||||
zone.addEventListener('drop', handleDrop, false);
|
||||
$(document).off('submit', '#frmSelectGallery').on('submit', '#frmSelectGallery', function (e) {
|
||||
preventDefaults(e);
|
||||
|
||||
// Handle browse selected files
|
||||
dataRefs.input.addEventListener('change', event => {
|
||||
dataRefs.files = event.target.files;
|
||||
handleFiles(dataRefs);
|
||||
}, false);
|
||||
|
||||
}
|
||||
|
||||
// Initialise ALL dropzones
|
||||
const dropZones = document.querySelectorAll('.upload_drop');
|
||||
for (const zone of dropZones) {
|
||||
eventHandlers(zone);
|
||||
}
|
||||
|
||||
// No 'image/gif' or PDF or webp allowed here, but it's up to your use case.
|
||||
// Double checks the input "accept" attribute
|
||||
const isImageFile = file => ['image/jpeg', 'image/png'].includes(file.type);
|
||||
|
||||
// Based on: https://flaviocopes.com/how-to-upload-files-fetch/
|
||||
const imageUpload = dataRefs => {
|
||||
|
||||
// Multiple source routes, so double check validity
|
||||
if (!dataRefs.files || !dataRefs.input) {
|
||||
displayMessage(`Upload`, `No files were detected to upload`);
|
||||
return;
|
||||
}
|
||||
|
||||
const galleryId = dataRefs.input.getAttribute('data-post-gallery-id');
|
||||
if (!galleryId) {
|
||||
displayMessage(`Upload`, `Invalid gallery Id detected`);
|
||||
return;
|
||||
}
|
||||
|
||||
const url = dataRefs.input.getAttribute('data-post-url');
|
||||
if (!url) {
|
||||
displayMessage(`Upload`, `Could not find upload Url`);
|
||||
return;
|
||||
}
|
||||
|
||||
const secretKey = dataRefs.input.getAttribute('data-post-key');
|
||||
|
||||
const formData = new FormData();
|
||||
formData.append('SecretKey', secretKey);
|
||||
formData.append('GalleryId', galleryId);
|
||||
for (var i = 0; i < dataRefs.files.length; i++) {
|
||||
formData.append(dataRefs.files[i].name, dataRefs.files[i]);
|
||||
}
|
||||
|
||||
displayLoader('Uploading...');
|
||||
|
||||
fetch(url, {
|
||||
method: 'POST',
|
||||
body: formData
|
||||
})
|
||||
.then(response => response.json())
|
||||
.then(data => {
|
||||
hideLoader();
|
||||
|
||||
if (data.success === true) {
|
||||
if (data.requiresReview === true) {
|
||||
displayMessage(`Upload`, `Successfully uploaded ${data.uploaded} photo(s) pending review`, data.errors);
|
||||
} else {
|
||||
displayMessage(`Upload`, `Successfully uploaded ${data.uploaded} photo(s)`, data.errors);
|
||||
}
|
||||
} else if (data.message) {
|
||||
displayMessage(`Upload`, `Upload failed`, [data.message]);
|
||||
var galleryId = $('input#gallery-id').val();
|
||||
var secretKey = $('input#gallery-key').val();
|
||||
if (galleryId && galleryId.length > 0) {
|
||||
var url = `/Gallery?id=${galleryId}`;
|
||||
if (secretKey && secretKey.length > 0) {
|
||||
url = `${url}&key=${secretKey}`;
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
hideLoader();
|
||||
displayMessage(`Upload`, `Upload failed`, [error]);
|
||||
});
|
||||
}
|
||||
|
||||
// Handle both selected and dropped files
|
||||
const handleFiles = dataRefs => {
|
||||
|
||||
let files = [...dataRefs.files];
|
||||
|
||||
// Remove unaccepted file types
|
||||
files = files.filter(item => {
|
||||
if (!isImageFile(item)) {
|
||||
console.log('Not an image, ', item.type);
|
||||
window.location = url;
|
||||
} else {
|
||||
displayMessage(`Gallery`, `Please select a valid gallery name`);
|
||||
}
|
||||
return isImageFile(item) ? item : null;
|
||||
});
|
||||
|
||||
if (!files.length) return;
|
||||
dataRefs.files = files;
|
||||
$(document).off('submit', '#frmAdminLogin').on('submit', '#frmAdminLogin', function (e) {
|
||||
preventDefaults(e);
|
||||
|
||||
imageUpload(dataRefs);
|
||||
}
|
||||
|
||||
function reviewPhoto(element, action) {
|
||||
var galleryId = element.parent('.btn-group').data('gallery-id');
|
||||
if (!galleryId) {
|
||||
displayMessage(`Review`, `Could not find gallery Id`);
|
||||
return;
|
||||
}
|
||||
|
||||
var photoId = element.parent('.btn-group').data('photo-id')
|
||||
if (!photoId) {
|
||||
displayMessage(`Review`, `Could not find photo Id`);
|
||||
return;
|
||||
}
|
||||
|
||||
displayLoader('Loading...');
|
||||
|
||||
$.ajax({
|
||||
url: '/Admin/ReviewPhoto',
|
||||
method: 'POST',
|
||||
data: { galleryId, photoId, action }
|
||||
})
|
||||
.done(data => {
|
||||
hideLoader();
|
||||
|
||||
if (data.success === true) {
|
||||
element.closest('.pending-approval').remove();
|
||||
|
||||
if ($('.pending-approval').length == 0) {
|
||||
$('#gallery-review').addClass('visually-hidden');
|
||||
$('#no-review-msg').removeClass('visually-hidden');
|
||||
} else {
|
||||
$('#no-review-msg').addClass('visually-hidden');
|
||||
$('#gallery-review').removeClass('visually-hidden');
|
||||
}
|
||||
} else if (data.message) {
|
||||
displayMessage(`Review`, `Review failed`, [data.message]);
|
||||
}
|
||||
})
|
||||
.fail((xhr, error) => {
|
||||
hideLoader();
|
||||
displayMessage(`Review`, `Review failed`, [error]);
|
||||
});
|
||||
}
|
||||
|
||||
function displayMessage(title, message, errors) {
|
||||
$('#alert-message-modal .modal-title').text(title);
|
||||
$('#alert-message-modal .modal-message').html(message);
|
||||
|
||||
$('#alert-message-modal .modal-error').hide();
|
||||
if (errors && errors.length > 0) {
|
||||
var errorMessage = `<b>Errors:</b>`;
|
||||
errorMessage += `<ul>`;
|
||||
errors.forEach((error) => {
|
||||
errorMessage += `<li>${error}</li>`;
|
||||
});
|
||||
errorMessage += `</ul>`;
|
||||
$('#alert-message-modal .modal-error').html(errorMessage);
|
||||
$('#alert-message-modal .modal-error').show();
|
||||
} else {
|
||||
$('#alert-message-modal .modal-error').html('');
|
||||
}
|
||||
|
||||
$('#alert-message-modal').modal('show');
|
||||
}
|
||||
|
||||
function displayLoader(message) {
|
||||
$('body').loading({
|
||||
theme: 'dark',
|
||||
message,
|
||||
stoppable: false,
|
||||
start: true
|
||||
});
|
||||
}
|
||||
|
||||
function hideLoader() {
|
||||
$('body').loading('stop');
|
||||
}
|
||||
|
||||
function uuidv4() {
|
||||
return "10000000-1000-4000-8000-100000000000".replace(/[018]/g, c =>
|
||||
(+c ^ crypto.getRandomValues(new Uint8Array(1))[0] & 15 >> +c / 4).toString(16)
|
||||
);
|
||||
}
|
||||
|
||||
$(document).off('click', '.btn-reload').on('click', '.btn-reload', function () {
|
||||
window.location.reload();
|
||||
});
|
||||
|
||||
$(document).off('click', '#btnGenerateGalleryName').on('click', '#btnGenerateGalleryName', function (e) {
|
||||
preventDefaults(e);
|
||||
$('input#gallery-id').val(uuidv4());
|
||||
});
|
||||
|
||||
$(document).off('submit', '#frmSelectGallery').on('submit', '#frmSelectGallery', function (e) {
|
||||
preventDefaults(e);
|
||||
|
||||
var galleryId = $('input#gallery-id').val();
|
||||
var secretKey = $('input#gallery-key').val();
|
||||
if (galleryId && galleryId.length > 0) {
|
||||
var url = `/Gallery?id=${galleryId}`;
|
||||
if (secretKey && secretKey.length > 0) {
|
||||
url = `${url}&key=${secretKey}`;
|
||||
var password = $('input#admin-password').val();
|
||||
if (password === undefined || password.length === 0) {
|
||||
displayMessage(`Login`, `Please enter a valid password`);
|
||||
return;
|
||||
}
|
||||
|
||||
window.location = url;
|
||||
} else {
|
||||
displayMessage(`Gallery`, `Please select a valid gallery name`);
|
||||
}
|
||||
});
|
||||
displayLoader('Loading...');
|
||||
|
||||
$(document).off('submit', '#frmAdminLogin').on('submit', '#frmAdminLogin', function (e) {
|
||||
preventDefaults(e);
|
||||
|
||||
var password = $('input#admin-password').val();
|
||||
if (password === undefined || password.length === 0) {
|
||||
displayMessage(`Login`, `Please enter a valid password`);
|
||||
return;
|
||||
}
|
||||
|
||||
displayLoader('Loading...');
|
||||
|
||||
$.ajax({
|
||||
url: '/Admin/Login',
|
||||
method: 'POST',
|
||||
data: { Password: password }
|
||||
})
|
||||
.done(data => {
|
||||
hideLoader();
|
||||
|
||||
if (data.success === true) {
|
||||
window.location = `/Admin`;
|
||||
} else if (data.message) {
|
||||
displayMessage(`Login`, `Login failed`, [data.message]);
|
||||
}
|
||||
$.ajax({
|
||||
url: '/Admin/Login',
|
||||
method: 'POST',
|
||||
data: { Password: password }
|
||||
})
|
||||
.fail((xhr, error) => {
|
||||
hideLoader();
|
||||
displayMessage(`Login`, `Login failed`, [error]);
|
||||
});
|
||||
});
|
||||
.done(data => {
|
||||
hideLoader();
|
||||
|
||||
$(document).off('click', 'button.btnReviewApprove').on('click', 'button.btnReviewApprove', function (e) {
|
||||
preventDefaults(e);
|
||||
reviewPhoto($(this), 1);
|
||||
});
|
||||
if (data.success === true) {
|
||||
window.location = `/Admin`;
|
||||
} else if (data.message) {
|
||||
displayMessage(`Login`, `Login failed`, [data.message]);
|
||||
} else {
|
||||
displayMessage(`Login`, `Invalid username or password specified`);
|
||||
}
|
||||
})
|
||||
.fail((xhr, error) => {
|
||||
hideLoader();
|
||||
displayMessage(`Login`, `Login failed`, [error]);
|
||||
});
|
||||
});
|
||||
|
||||
$(document).off('click', 'button.btnReviewReject').on('click', 'button.btnReviewReject', function (e) {
|
||||
preventDefaults(e);
|
||||
reviewPhoto($(this), 2);
|
||||
});
|
||||
$(document).off('click', 'button.btnDismissPopup').on('click', 'button.btnDismissPopup', function (e) {
|
||||
preventDefaults(e);
|
||||
hidePopup($(this).closest('.modal').attr('id'));
|
||||
});
|
||||
|
||||
lightbox.option({
|
||||
'disableScrolling': true
|
||||
});
|
||||
})();
|
||||
@@ -1,7 +0,0 @@
|
||||
/*!
|
||||
* Start Bootstrap - Shop Homepage v5.0.6 (https://startbootstrap.com/template/shop-homepage)
|
||||
* Copyright 2013-2023 Start Bootstrap
|
||||
* Licensed under MIT (https://github.com/StartBootstrap/startbootstrap-shop-homepage/blob/master/LICENSE)
|
||||
*/
|
||||
// This file is intentionally blank
|
||||
// Use this file to add JavaScript to your project
|
||||
BIN
WeddingShare/wwwroot/webfonts/fa-brands-400.ttf
Normal file
BIN
WeddingShare/wwwroot/webfonts/fa-brands-400.ttf
Normal file
Binary file not shown.
BIN
WeddingShare/wwwroot/webfonts/fa-brands-400.woff2
Normal file
BIN
WeddingShare/wwwroot/webfonts/fa-brands-400.woff2
Normal file
Binary file not shown.
BIN
WeddingShare/wwwroot/webfonts/fa-regular-400.ttf
Normal file
BIN
WeddingShare/wwwroot/webfonts/fa-regular-400.ttf
Normal file
Binary file not shown.
BIN
WeddingShare/wwwroot/webfonts/fa-regular-400.woff2
Normal file
BIN
WeddingShare/wwwroot/webfonts/fa-regular-400.woff2
Normal file
Binary file not shown.
BIN
WeddingShare/wwwroot/webfonts/fa-solid-900.ttf
Normal file
BIN
WeddingShare/wwwroot/webfonts/fa-solid-900.ttf
Normal file
Binary file not shown.
BIN
WeddingShare/wwwroot/webfonts/fa-solid-900.woff2
Normal file
BIN
WeddingShare/wwwroot/webfonts/fa-solid-900.woff2
Normal file
Binary file not shown.
54
readme.md
54
readme.md
@@ -10,28 +10,39 @@ You are not limited to a single gallery. You can generate multiple gallerys all
|
||||
Warning. This is open source software (GPL-V3), and while we make a best effort to ensure releases are stable and bug-free,
|
||||
there are no warranties. Use at your own risk.
|
||||
|
||||
## Notes
|
||||
|
||||
Not all image formats are supported in browsers so although you may be able to add them via the ALLOWED_FILE_TYPES environment variable they may not be supported. One such format is Apples .heic format. It is specific to Apple devices and due to its licensing a lot of browsers have not implemented it.
|
||||
|
||||
## Settings
|
||||
| Name | Value |
|
||||
| ------------------- | ----------------------------- |
|
||||
| TITLE | WeddingShare |
|
||||
| LOGO | https://someurl/someimage.png |
|
||||
| GALLERY_COLUMNS | 4 |
|
||||
| ALLOWED_FILE_TYPES | .jpg,.jpeg,.png |
|
||||
| MAX_FILE_SIZE_MB | 10 |
|
||||
| SECRET_KEY | (optional) |
|
||||
| ADMIN_PASSWORD | admin |
|
||||
| SINGLE_GALLERY_MODE | false |
|
||||
| REQUIRE_REVIEW | true |
|
||||
| DISABLE_HOME_LINK | false |
|
||||
| DISABLE_REVIEW_COUNTER | false |
|
||||
| DISABLE_UPLOAD | false |
|
||||
| DISABLE_QR_CODE | false |
|
||||
| HIDE_KEY_FROM_QR_CODE | false |
|
||||
|
||||
| Name | Value |
|
||||
| ------------------------------ | ----------------------------- |
|
||||
| TITLE | WeddingShare |
|
||||
| LOGO | https://someurl/someimage.png |
|
||||
| FORCE_HTTPS | false |
|
||||
| GALLERY_COLUMNS | 4 |
|
||||
| ALLOWED_FILE_TYPES | .jpg,.jpeg,.png |
|
||||
| MAX_FILE_SIZE_MB | 10 |
|
||||
| THUMBNAIL_SIZE | 720 |
|
||||
| SECRET_KEY | (optional) |
|
||||
| SECRET_KEY_{GalleryId} | (optional) |
|
||||
| ADMIN_PASSWORD | admin |
|
||||
| SINGLE_GALLERY_MODE | false |
|
||||
| REQUIRE_REVIEW | true |
|
||||
| DISABLE_HOME_LINK | false |
|
||||
| DISABLE_REVIEW_COUNTER | false |
|
||||
| DISABLE_UPLOAD | false |
|
||||
| DISABLE_QR_CODE | false |
|
||||
| DISABLE_GUEST_GALLERY_CREATION | true |
|
||||
| HIDE_KEY_FROM_QR_CODE | false |
|
||||
| IDLE_GALLERY_REFRESH_MINS | 5 (0 = disable) |
|
||||
| DIRECTORY_SCANNER_INTERVAL | */30 * * * * (cron) |
|
||||
|
||||
## Docker Run
|
||||
|
||||
```
|
||||
docker run --name WeddingShare -h wedding-share -p 8080:5000 -v /var/lib/docker/volumes/wedding-share/_data:/app/wwwroot/uploads:rw --restart always cirx08/wedding_share:latest
|
||||
docker run --name WeddingShare -h wedding-share -p 8080:5000 -v /var/lib/docker/volumes/wedding-share-config/_data:/app/config:rw -v /var/lib/docker/volumes/wedding-share-uploads/_data:/app/wwwroot/uploads:rw --restart always cirx08/wedding_share:latest
|
||||
```
|
||||
|
||||
## Docker Compose
|
||||
@@ -51,14 +62,17 @@ services:
|
||||
MAX_FILE_SIZE_MB: 10
|
||||
SECRET_KEY: 'password'
|
||||
volumes:
|
||||
- data-volume:/app/wwwroot/uploads
|
||||
- data-volume-config:/app/config
|
||||
- data-volume-uploads:/app/wwwroot/uploads
|
||||
network_mode: bridge
|
||||
hostname: wedding-share
|
||||
restart: always
|
||||
|
||||
volumes:
|
||||
data-volume:
|
||||
name: WeddingShare
|
||||
data-volume-config:
|
||||
name: WeddingShare-Config
|
||||
data-volume-uploads:
|
||||
name: WeddingShare-Uploads
|
||||
```
|
||||
|
||||
## Links
|
||||
|
||||
Reference in New Issue
Block a user