Compare commits
47 Commits
v2.0.4
...
v2.0.5-lib
Author | SHA1 | Date | |
---|---|---|---|
c9bc8227bb | |||
4ea9371c00 | |||
326c74cdc6 | |||
f11c2efa8c | |||
6dd8102a82 | |||
ddf6a4955f | |||
602994e213 | |||
7c7306bf96 | |||
c24894b5de | |||
e10412c530 | |||
5c2491b6c3 | |||
036373032c | |||
db58dabd31 | |||
7ef98c05fa | |||
6351f43b9b | |||
6613c8a6c1 | |||
2b97882b42 | |||
925f386bed | |||
0fbbd54b0c | |||
12ba1fed00 | |||
2826bac53c | |||
3e7e9f354f | |||
86ff80885d | |||
be03e34406 | |||
83231becba | |||
876ee49fb0 | |||
10bec31033 | |||
fc48f29575 | |||
f0d9a452bb | |||
c03a4f83d1 | |||
10f06fde5c | |||
36b533cb16 | |||
6ff2cdab98 | |||
ef5cad1bf0 | |||
b60c7ecd9e | |||
68aaa8fee2 | |||
67bf14d428 | |||
c22ff77c89 | |||
84fc0ab1bd | |||
beb06f2f7f | |||
7cf30836bf | |||
e7ba289d06 | |||
d255ff4fd0 | |||
bcf19f4f3e | |||
efeee0e276 | |||
e789873eca | |||
14b9b76e87 |
51
.github/workflows/build.yml
vendored
51
.github/workflows/build.yml
vendored
@ -25,22 +25,12 @@ jobs:
|
||||
with:
|
||||
node-version: '16'
|
||||
|
||||
# - name: Setup docker
|
||||
# uses: docker-practice/actions-setup-docker@master
|
||||
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v2
|
||||
with:
|
||||
ref: v2
|
||||
path: alist
|
||||
|
||||
- name: Checkout web repo
|
||||
uses: actions/checkout@v2
|
||||
with:
|
||||
repository: Xhofe/alist-web
|
||||
ref: v2
|
||||
path: alist-web
|
||||
|
||||
- name: Set up xgo
|
||||
run: |
|
||||
docker pull techknowlogick/xgo:latest
|
||||
@ -50,10 +40,49 @@ jobs:
|
||||
- name: Build
|
||||
run: |
|
||||
mv alist/build.sh .
|
||||
bash build.sh
|
||||
bash build.sh web
|
||||
mv dist/* alist/public
|
||||
bash build.sh build
|
||||
|
||||
- name: Upload artifact
|
||||
uses: actions/upload-artifact@v2
|
||||
with:
|
||||
name: artifact
|
||||
path: alist/build
|
||||
docker:
|
||||
name: Docker
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v2
|
||||
- name: Docker meta
|
||||
id: meta
|
||||
uses: docker/metadata-action@v3
|
||||
with:
|
||||
images: xhofe/alist
|
||||
- name: Set up Node
|
||||
uses: actions/setup-node@v2
|
||||
with:
|
||||
node-version: '16'
|
||||
- name: Build web
|
||||
run: |
|
||||
bash build.sh web
|
||||
mv dist/* public
|
||||
- name: Set up QEMU
|
||||
uses: docker/setup-qemu-action@v1
|
||||
- name: Set up Docker Buildx
|
||||
uses: docker/setup-buildx-action@v1
|
||||
- name: Login to DockerHub
|
||||
uses: docker/login-action@v1
|
||||
with:
|
||||
username: xhofe
|
||||
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
||||
- name: Build and push
|
||||
id: docker_build
|
||||
uses: docker/build-push-action@v2
|
||||
with:
|
||||
context: .
|
||||
push: true
|
||||
tags: ${{ steps.meta.outputs.tags }}
|
||||
labels: ${{ steps.meta.outputs.labels }}
|
||||
platforms: linux/amd64,linux/arm64,linux/arm/v7,linux/386,linux/arm/v6,linux/s390x
|
48
.github/workflows/docker.yml
vendored
48
.github/workflows/docker.yml
vendored
@ -1,48 +0,0 @@
|
||||
name: docker
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- 'v2'
|
||||
tags:
|
||||
- 'v*'
|
||||
pull_request:
|
||||
branches:
|
||||
- 'v2'
|
||||
|
||||
jobs:
|
||||
docker:
|
||||
name: Docker
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v2
|
||||
- name: Docker meta
|
||||
id: meta
|
||||
uses: docker/metadata-action@v3
|
||||
with:
|
||||
images: xhofe/alist
|
||||
- name: Set up Node
|
||||
uses: actions/setup-node@v2
|
||||
with:
|
||||
node-version: '16'
|
||||
- name: Build web
|
||||
run: bash build.sh web
|
||||
- name: Set up QEMU
|
||||
uses: docker/setup-qemu-action@v1
|
||||
- name: Set up Docker Buildx
|
||||
uses: docker/setup-buildx-action@v1
|
||||
- name: Login to DockerHub
|
||||
uses: docker/login-action@v1
|
||||
with:
|
||||
username: xhofe
|
||||
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
||||
- name: Build and push
|
||||
id: docker_build
|
||||
uses: docker/build-push-action@v2
|
||||
with:
|
||||
context: .
|
||||
push: true
|
||||
tags: ${{ steps.meta.outputs.tags }}
|
||||
labels: ${{ steps.meta.outputs.labels }}
|
||||
platforms: linux/amd64,linux/arm64,linux/arm/v7,linux/386,linux/arm/v6,linux/s390x
|
66
.github/workflows/release.yml
vendored
66
.github/workflows/release.yml
vendored
@ -19,14 +19,6 @@ jobs:
|
||||
with:
|
||||
go-version: ${{ matrix.go-version }}
|
||||
|
||||
# - name: Setup docker
|
||||
# uses: docker-practice/actions-setup-docker@master
|
||||
|
||||
- name: Setup Node
|
||||
uses: actions/setup-node@v2
|
||||
with:
|
||||
node-version: '16'
|
||||
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v2
|
||||
with:
|
||||
@ -35,15 +27,6 @@ jobs:
|
||||
persist-credentials: false
|
||||
fetch-depth: 0
|
||||
|
||||
- name: Checkout web repo
|
||||
uses: actions/checkout@v2
|
||||
with:
|
||||
repository: Xhofe/alist-web
|
||||
ref: v2
|
||||
path: alist-web
|
||||
persist-credentials: false
|
||||
fetch-depth: 0
|
||||
|
||||
- name: Set up xgo
|
||||
run: |
|
||||
docker pull techknowlogick/xgo:latest
|
||||
@ -53,17 +36,48 @@ jobs:
|
||||
- name: Build
|
||||
run: |
|
||||
mv alist/build.sh .
|
||||
bash build.sh cdn
|
||||
mv dist/* alist/public
|
||||
bash build.sh release
|
||||
|
||||
- name: Upload asserts files
|
||||
uses: ad-m/github-push-action@master
|
||||
with:
|
||||
github_token: ${{ secrets.MY_TOKEN }}
|
||||
branch: cdn
|
||||
directory: alist-web
|
||||
repository: Xhofe/alist-web
|
||||
|
||||
- name: Release
|
||||
uses: softprops/action-gh-release@v1
|
||||
with:
|
||||
files: alist/build/compress/*
|
||||
files: alist/build/compress/*
|
||||
docker:
|
||||
name: Docker
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v2
|
||||
- name: Docker meta
|
||||
id: meta
|
||||
uses: docker/metadata-action@v3
|
||||
with:
|
||||
images: xhofe/alist
|
||||
- name: Set up Node
|
||||
uses: actions/setup-node@v2
|
||||
with:
|
||||
node-version: '16'
|
||||
- name: Build web
|
||||
run: |
|
||||
bash build.sh cdn
|
||||
mv dist/* public
|
||||
- name: Set up QEMU
|
||||
uses: docker/setup-qemu-action@v1
|
||||
- name: Set up Docker Buildx
|
||||
uses: docker/setup-buildx-action@v1
|
||||
- name: Login to DockerHub
|
||||
uses: docker/login-action@v1
|
||||
with:
|
||||
username: xhofe
|
||||
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
||||
- name: Build and push
|
||||
id: docker_build
|
||||
uses: docker/build-push-action@v2
|
||||
with:
|
||||
context: .
|
||||
push: true
|
||||
tags: ${{ steps.meta.outputs.tags }}
|
||||
labels: ${{ steps.meta.outputs.labels }}
|
||||
platforms: linux/amd64,linux/arm64,linux/arm/v7,linux/386,linux/arm/v6,linux/s390x
|
674
LICENSE
674
LICENSE
@ -1,21 +1,661 @@
|
||||
MIT License
|
||||
GNU AFFERO GENERAL PUBLIC LICENSE
|
||||
Version 3, 19 November 2007
|
||||
|
||||
Copyright (c) 2020 Xhofe
|
||||
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.
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
Preamble
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
The GNU Affero General Public License is a free, copyleft license for
|
||||
software and other kinds of works, specifically designed to ensure
|
||||
cooperation with the community in the case of network server software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
The licenses for most software and other practical works are designed
|
||||
to take away your freedom to share and change the works. By contrast,
|
||||
our General Public Licenses are 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.
|
||||
|
||||
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.
|
||||
|
||||
Developers that use our General Public Licenses protect your rights
|
||||
with two steps: (1) assert copyright on the software, and (2) offer
|
||||
you this License which gives you legal permission to copy, distribute
|
||||
and/or modify the software.
|
||||
|
||||
A secondary benefit of defending all users' freedom is that
|
||||
improvements made in alternate versions of the program, if they
|
||||
receive widespread use, become available for other developers to
|
||||
incorporate. Many developers of free software are heartened and
|
||||
encouraged by the resulting cooperation. However, in the case of
|
||||
software used on network servers, this result may fail to come about.
|
||||
The GNU General Public License permits making a modified version and
|
||||
letting the public access it on a server without ever releasing its
|
||||
source code to the public.
|
||||
|
||||
The GNU Affero General Public License is designed specifically to
|
||||
ensure that, in such cases, the modified source code becomes available
|
||||
to the community. It requires the operator of a network server to
|
||||
provide the source code of the modified version running there to the
|
||||
users of that server. Therefore, public use of a modified version, on
|
||||
a publicly accessible server, gives the public access to the source
|
||||
code of the modified version.
|
||||
|
||||
An older license, called the Affero General Public License and
|
||||
published by Affero, was designed to accomplish similar goals. This is
|
||||
a different license, not a version of the Affero GPL, but Affero has
|
||||
released a new version of the Affero GPL which permits relicensing under
|
||||
this license.
|
||||
|
||||
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 Affero 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. Remote Network Interaction; Use with the GNU General Public License.
|
||||
|
||||
Notwithstanding any other provision of this License, if you modify the
|
||||
Program, your modified version must prominently offer all users
|
||||
interacting with it remotely through a computer network (if your version
|
||||
supports such interaction) an opportunity to receive the Corresponding
|
||||
Source of your version by providing access to the Corresponding Source
|
||||
from a network server at no charge, through some standard or customary
|
||||
means of facilitating copying of software. This Corresponding Source
|
||||
shall include the Corresponding Source for any work covered by version 3
|
||||
of the GNU General Public License that is incorporated pursuant to the
|
||||
following paragraph.
|
||||
|
||||
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 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 work with which it is combined will remain governed by version
|
||||
3 of the GNU General Public License.
|
||||
|
||||
14. Revised Versions of this License.
|
||||
|
||||
The Free Software Foundation may publish revised and/or new versions of
|
||||
the GNU Affero 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 Affero 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 Affero 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 Affero 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 Affero 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 Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero 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 your software can interact with users remotely through a computer
|
||||
network, you should also make sure that it provides a way for users to
|
||||
get its source. For example, if your program is a web application, its
|
||||
interface could display a "Source" link that leads users to an archive
|
||||
of the code. There are many ways you could offer source, and different
|
||||
solutions will be better for different programs; see section 13 for the
|
||||
specific requirements.
|
||||
|
||||
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 AGPL, see
|
||||
<https://www.gnu.org/licenses/>.
|
17
README.md
17
README.md
@ -18,20 +18,23 @@ English | [中文](./README_cn.md)
|
||||
|
||||
## Features
|
||||
|
||||
- [x] multiple storage
|
||||
- [x] Multiple storage
|
||||
- [x] Local storage
|
||||
- [x] [aliyundrive](https://www.aliyundrive.com/)
|
||||
- [x] OneDrive / Sharepoint ([global](https://www.office.com/), [cn](https://portal.partner.microsoftonline.cn),de,us)
|
||||
- [x] [Aliyundrive](https://www.aliyundrive.com/)
|
||||
- [x] OneDrive / Sharepoint ([global](https://www.office.com/), [cn](https://portal.partner.microsoftonline.cn),de,us)
|
||||
- [x] [189cloud](https://cloud.189.cn)
|
||||
- [x] [GoogleDrive](https://drive.google.com/)
|
||||
- [x] [123pan](https://www.123pan.com/)
|
||||
- [x] [lanzou](https://pc.woozooo.com/)
|
||||
- [x] [Lanzou](https://pc.woozooo.com/)
|
||||
- [x] [Alist](https://github.com/Xhofe/alist)
|
||||
- [x] FTP
|
||||
- [x] [PikPak](https://www.mypikpak.com/)
|
||||
- [x] [ShandianPan](https://shandianpan.com/)
|
||||
- [x] [S3](https://aws.amazon.com/s3/)
|
||||
- [x] WebDav
|
||||
- [x] Teambition([China](https://www.teambition.com/ ),[International](https://us.teambition.com/ ))
|
||||
- [x] [Mediatrack](https://www.mediatrack.cn/)
|
||||
- [x] [139yun](https://yun.139.com/) (Personal, Family)
|
||||
- [x] Easy to deploy and out-of-the-box
|
||||
- [x] File preview (PDF, markdown, code, plain text, ...)
|
||||
- [x] Image preview in gallery mode
|
||||
@ -42,12 +45,12 @@ English | [中文](./README_cn.md)
|
||||
- [x] Dark mode
|
||||
- [x] I18n
|
||||
- [x] Protected routes (password protection and authentication)
|
||||
- [x] WebDav (A small part readonly, see https://alist-doc.nn.ci/en/docs/intro for details)
|
||||
- [x] WebDav (see https://alist-doc.nn.ci/en/docs/webdav for details)
|
||||
- [x] [Docker Deploy](https://hub.docker.com/r/xhofe/alist)
|
||||
- [x] Cloudflare workers proxy
|
||||
- [x] File/Folder package download
|
||||
- [x] Support video list playback and subtitles(ass,srt,vtt)
|
||||
- [x] Web upload(Can allow visitors to upload)
|
||||
- [x] Web upload(Can allow visitors to upload) and delete
|
||||
|
||||
## Discussion
|
||||
|
||||
@ -65,7 +68,7 @@ Available at: <https://alist.nn.ci>.
|
||||
|
||||
## License
|
||||
|
||||
The `AList` is open-source software licensed under the MIT license.
|
||||
The `AList` is open-source software licensed under the AGPL-3.0 license.
|
||||
|
||||
---
|
||||
|
||||
|
@ -31,6 +31,9 @@
|
||||
- [x] [闪电盘](https://shandianpan.com/)
|
||||
- [x] [S3](https://aws.amazon.com/cn/s3/)
|
||||
- [x] WebDav
|
||||
- [x] Teambition([中国](https://www.teambition.com/ ),[国际](https://us.teambition.com/ ))
|
||||
- [x] [分秒帧](https://www.mediatrack.cn/)
|
||||
- [x] [和彩云](https://yun.139.com/) (个人云, 家庭云)
|
||||
- [x] 部署方便,开箱即用
|
||||
- [x] 文件预览(PDF、markdown、代码、纯文本……)
|
||||
- [x] 画廊模式下的图像预览
|
||||
@ -41,12 +44,12 @@
|
||||
- [x] 黑暗模式
|
||||
- [x] 国际化
|
||||
- [x] 受保护的路由(密码保护和身份验证)
|
||||
- [x] WebDav(少部分只读,具体见https://alist-doc.nn.ci/docs/intro )
|
||||
- [x] WebDav(具体见https://alist-doc.nn.ci/docs/webdav )
|
||||
- [x] [Docker 部署](https://hub.docker.com/r/xhofe/alist)
|
||||
- [x] Cloudflare workers 中转
|
||||
- [x] 文件/文件夹打包下载
|
||||
- [x] 支持视频列表播放和字幕(ass,srt,vtt)
|
||||
- [x] 网页上传(可以允许访客上传)
|
||||
- [x] 网页上传(可以允许访客上传),删除
|
||||
|
||||
## 讨论
|
||||
|
||||
@ -64,7 +67,7 @@
|
||||
|
||||
## 许可
|
||||
|
||||
`AList` 是在 MIT 许可下许可的开源软件。
|
||||
`AList` 是在 AGPL-3.0 许可下许可的开源软件。
|
||||
|
||||
---
|
||||
|
||||
|
430
alist-proxy.js
430
alist-proxy.js
@ -1,430 +0,0 @@
|
||||
const HOST = "YOUR_HOST";
|
||||
const TOKEN = "YOUR_TOKEN";
|
||||
|
||||
addEventListener("fetch", (event) => {
|
||||
const request = event.request;
|
||||
const url = new URL(request.url);
|
||||
const sign = url.searchParams.get("sign");
|
||||
if (request.method === "OPTIONS") {
|
||||
// Handle CORS preflight requests
|
||||
event.respondWith(handleOptions(request));
|
||||
} else if (sign && sign.length === 16) {
|
||||
// Handle requests to the Down server
|
||||
event.respondWith(handleDownload(request));
|
||||
} else {
|
||||
// Handle requests to the API server
|
||||
event.respondWith(handleRequest(event));
|
||||
}
|
||||
});
|
||||
|
||||
const corsHeaders = {
|
||||
"Access-Control-Allow-Origin": "*",
|
||||
"Access-Control-Allow-Methods": "GET,HEAD,POST,OPTIONS",
|
||||
"Access-Control-Max-Age": "86400",
|
||||
};
|
||||
|
||||
async function handleDownload(request) {
|
||||
const origin = request.headers.get("origin");
|
||||
const url = new URL(request.url);
|
||||
const path = decodeURI(url.pathname);
|
||||
const sign = url.searchParams.get("sign");
|
||||
const name = path.split("/").pop();
|
||||
const right = md5(`alist-${TOKEN}-${name}`).slice(8, 24);
|
||||
if (sign !== right) {
|
||||
const resp = new Response(
|
||||
JSON.stringify({
|
||||
code: 401,
|
||||
message: `sign mismatch`,
|
||||
}),
|
||||
{
|
||||
headers: {
|
||||
"content-type": "application/json;charset=UTF-8",
|
||||
},
|
||||
}
|
||||
);
|
||||
resp.headers.set("Access-Control-Allow-Origin", origin);
|
||||
return resp;
|
||||
}
|
||||
|
||||
let resp = await fetch(`${HOST}/api/admin/link`, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"content-type": "application/json;charset=UTF-8",
|
||||
Authorization: TOKEN,
|
||||
},
|
||||
body: JSON.stringify({
|
||||
path: path,
|
||||
}),
|
||||
});
|
||||
let res = await resp.json();
|
||||
if (res.code !== 200) {
|
||||
return new Response(JSON.stringify(res));
|
||||
}
|
||||
request = new Request(res.data.url, request);
|
||||
if (res.data.headers) {
|
||||
for (const header of res.data.headers) {
|
||||
request.headers.set(header.name, header.value);
|
||||
}
|
||||
}
|
||||
let response = await fetch(request);
|
||||
|
||||
// Recreate the response so we can modify the headers
|
||||
response = new Response(response.body, response);
|
||||
|
||||
// Set CORS headers
|
||||
response.headers.set("Access-Control-Allow-Origin", origin);
|
||||
|
||||
// Append to/Add Vary header so browser will cache response correctly
|
||||
response.headers.append("Vary", "Origin");
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
/**
|
||||
* Respond to the request
|
||||
* @param {Request} request
|
||||
*/
|
||||
async function handleRequest(event) {
|
||||
const { request } = event;
|
||||
|
||||
//请求头部、返回对象
|
||||
let reqHeaders = new Headers(request.headers),
|
||||
outBody,
|
||||
outStatus = 200,
|
||||
outStatusText = "OK",
|
||||
outCt = null,
|
||||
outHeaders = new Headers({
|
||||
"Access-Control-Allow-Origin": reqHeaders.get("Origin"),
|
||||
"Access-Control-Allow-Methods": "GET, POST, PUT, PATCH, DELETE, OPTIONS",
|
||||
"Access-Control-Allow-Headers":
|
||||
reqHeaders.get("Access-Control-Allow-Headers") ||
|
||||
"Accept, Authorization, Cache-Control, Content-Type, DNT, If-Modified-Since, Keep-Alive, Origin, User-Agent, X-Requested-With, Token, x-access-token, Notion-Version",
|
||||
});
|
||||
|
||||
try {
|
||||
//取域名第一个斜杠后的所有信息为代理链接
|
||||
let url = request.url.substr(8);
|
||||
url = decodeURIComponent(url.substr(url.indexOf("/") + 1));
|
||||
|
||||
//需要忽略的代理
|
||||
if (
|
||||
request.method == "OPTIONS" &&
|
||||
reqHeaders.has("access-control-request-headers")
|
||||
) {
|
||||
//输出提示
|
||||
return new Response(null, PREFLIGHT_INIT);
|
||||
} else if (
|
||||
url.length < 3 ||
|
||||
url.indexOf(".") == -1 ||
|
||||
url == "favicon.ico" ||
|
||||
url == "robots.txt"
|
||||
) {
|
||||
return Response.redirect("https://baidu.com", 301);
|
||||
}
|
||||
//阻断
|
||||
else if (blocker.check(url)) {
|
||||
return Response.redirect("https://baidu.com", 301);
|
||||
} else {
|
||||
//补上前缀 http://
|
||||
url = url
|
||||
.replace(/https:(\/)*/, "https://")
|
||||
.replace(/http:(\/)*/, "http://");
|
||||
if (url.indexOf("://") == -1) {
|
||||
url = "http://" + url;
|
||||
}
|
||||
//构建 fetch 参数
|
||||
let fp = {
|
||||
method: request.method,
|
||||
headers: {},
|
||||
};
|
||||
|
||||
//保留头部其它信息
|
||||
let he = reqHeaders.entries();
|
||||
for (let h of he) {
|
||||
if (!["content-length"].includes(h[0])) {
|
||||
fp.headers[h[0]] = h[1];
|
||||
}
|
||||
}
|
||||
// 是否带 body
|
||||
if (["POST", "PUT", "PATCH", "DELETE"].indexOf(request.method) >= 0) {
|
||||
const ct = (reqHeaders.get("content-type") || "").toLowerCase();
|
||||
if (ct.includes("application/json")) {
|
||||
let requestJSON = await request.json();
|
||||
console.log(typeof requestJSON);
|
||||
fp.body = JSON.stringify(requestJSON);
|
||||
} else if (
|
||||
ct.includes("application/text") ||
|
||||
ct.includes("text/html")
|
||||
) {
|
||||
fp.body = await request.text();
|
||||
} else if (ct.includes("form")) {
|
||||
// fp.body = await request.formData();
|
||||
fp.body = await request.text();
|
||||
} else {
|
||||
fp.body = await request.blob();
|
||||
}
|
||||
}
|
||||
// 发起 fetch
|
||||
let fr = await fetch(url, fp);
|
||||
outCt = fr.headers.get("content-type");
|
||||
if (outCt.includes("application/text") || outCt.includes("text/html")) {
|
||||
try {
|
||||
// 添加base
|
||||
let newFr = new HTMLRewriter()
|
||||
.on("head", {
|
||||
element(element) {
|
||||
element.prepend(`<base href="${url}" />`, {
|
||||
html: true,
|
||||
});
|
||||
},
|
||||
})
|
||||
.transform(fr);
|
||||
fr = newFr;
|
||||
} catch (e) {}
|
||||
}
|
||||
outStatus = fr.status;
|
||||
outStatusText = fr.statusText;
|
||||
outBody = fr.body;
|
||||
}
|
||||
} catch (err) {
|
||||
outCt = "application/json";
|
||||
outBody = JSON.stringify({
|
||||
code: -1,
|
||||
msg: JSON.stringify(err.stack) || err,
|
||||
});
|
||||
}
|
||||
|
||||
//设置类型
|
||||
if (outCt && outCt != "") {
|
||||
outHeaders.set("content-type", outCt);
|
||||
}
|
||||
|
||||
let response = new Response(outBody, {
|
||||
status: outStatus,
|
||||
statusText: outStatusText,
|
||||
headers: outHeaders,
|
||||
});
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
const blocker = {
|
||||
keys: [],
|
||||
check: function (url) {
|
||||
url = url.toLowerCase();
|
||||
let len = blocker.keys.filter((x) => url.includes(x)).length;
|
||||
return len != 0;
|
||||
},
|
||||
};
|
||||
|
||||
function handleOptions(request) {
|
||||
// Make sure the necessary headers are present
|
||||
// for this to be a valid pre-flight request
|
||||
let headers = request.headers;
|
||||
if (
|
||||
headers.get("Origin") !== null &&
|
||||
headers.get("Access-Control-Request-Method") !== null
|
||||
// && headers.get("Access-Control-Request-Headers") !== null
|
||||
) {
|
||||
// Handle CORS pre-flight request.
|
||||
// If you want to check or reject the requested method + headers
|
||||
// you can do that here.
|
||||
let respHeaders = {
|
||||
...corsHeaders,
|
||||
// Allow all future content Request headers to go back to browser
|
||||
// such as Authorization (Bearer) or X-Client-Name-Version
|
||||
"Access-Control-Allow-Headers": request.headers.get(
|
||||
"Access-Control-Request-Headers"
|
||||
),
|
||||
};
|
||||
|
||||
return new Response(null, {
|
||||
headers: respHeaders,
|
||||
});
|
||||
} else {
|
||||
// Handle standard OPTIONS request.
|
||||
// If you want to allow other HTTP Methods, you can do that here.
|
||||
return new Response(null, {
|
||||
headers: {
|
||||
Allow: "GET, HEAD, POST, OPTIONS",
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
!(function (a) {
|
||||
"use strict";
|
||||
function b(a, b) {
|
||||
var c = (65535 & a) + (65535 & b),
|
||||
d = (a >> 16) + (b >> 16) + (c >> 16);
|
||||
return (d << 16) | (65535 & c);
|
||||
}
|
||||
function c(a, b) {
|
||||
return (a << b) | (a >>> (32 - b));
|
||||
}
|
||||
function d(a, d, e, f, g, h) {
|
||||
return b(c(b(b(d, a), b(f, h)), g), e);
|
||||
}
|
||||
function e(a, b, c, e, f, g, h) {
|
||||
return d((b & c) | (~b & e), a, b, f, g, h);
|
||||
}
|
||||
function f(a, b, c, e, f, g, h) {
|
||||
return d((b & e) | (c & ~e), a, b, f, g, h);
|
||||
}
|
||||
function g(a, b, c, e, f, g, h) {
|
||||
return d(b ^ c ^ e, a, b, f, g, h);
|
||||
}
|
||||
function h(a, b, c, e, f, g, h) {
|
||||
return d(c ^ (b | ~e), a, b, f, g, h);
|
||||
}
|
||||
function i(a, c) {
|
||||
(a[c >> 5] |= 128 << c % 32), (a[(((c + 64) >>> 9) << 4) + 14] = c);
|
||||
var d,
|
||||
i,
|
||||
j,
|
||||
k,
|
||||
l,
|
||||
m = 1732584193,
|
||||
n = -271733879,
|
||||
o = -1732584194,
|
||||
p = 271733878;
|
||||
for (d = 0; d < a.length; d += 16)
|
||||
(i = m),
|
||||
(j = n),
|
||||
(k = o),
|
||||
(l = p),
|
||||
(m = e(m, n, o, p, a[d], 7, -680876936)),
|
||||
(p = e(p, m, n, o, a[d + 1], 12, -389564586)),
|
||||
(o = e(o, p, m, n, a[d + 2], 17, 606105819)),
|
||||
(n = e(n, o, p, m, a[d + 3], 22, -1044525330)),
|
||||
(m = e(m, n, o, p, a[d + 4], 7, -176418897)),
|
||||
(p = e(p, m, n, o, a[d + 5], 12, 1200080426)),
|
||||
(o = e(o, p, m, n, a[d + 6], 17, -1473231341)),
|
||||
(n = e(n, o, p, m, a[d + 7], 22, -45705983)),
|
||||
(m = e(m, n, o, p, a[d + 8], 7, 1770035416)),
|
||||
(p = e(p, m, n, o, a[d + 9], 12, -1958414417)),
|
||||
(o = e(o, p, m, n, a[d + 10], 17, -42063)),
|
||||
(n = e(n, o, p, m, a[d + 11], 22, -1990404162)),
|
||||
(m = e(m, n, o, p, a[d + 12], 7, 1804603682)),
|
||||
(p = e(p, m, n, o, a[d + 13], 12, -40341101)),
|
||||
(o = e(o, p, m, n, a[d + 14], 17, -1502002290)),
|
||||
(n = e(n, o, p, m, a[d + 15], 22, 1236535329)),
|
||||
(m = f(m, n, o, p, a[d + 1], 5, -165796510)),
|
||||
(p = f(p, m, n, o, a[d + 6], 9, -1069501632)),
|
||||
(o = f(o, p, m, n, a[d + 11], 14, 643717713)),
|
||||
(n = f(n, o, p, m, a[d], 20, -373897302)),
|
||||
(m = f(m, n, o, p, a[d + 5], 5, -701558691)),
|
||||
(p = f(p, m, n, o, a[d + 10], 9, 38016083)),
|
||||
(o = f(o, p, m, n, a[d + 15], 14, -660478335)),
|
||||
(n = f(n, o, p, m, a[d + 4], 20, -405537848)),
|
||||
(m = f(m, n, o, p, a[d + 9], 5, 568446438)),
|
||||
(p = f(p, m, n, o, a[d + 14], 9, -1019803690)),
|
||||
(o = f(o, p, m, n, a[d + 3], 14, -187363961)),
|
||||
(n = f(n, o, p, m, a[d + 8], 20, 1163531501)),
|
||||
(m = f(m, n, o, p, a[d + 13], 5, -1444681467)),
|
||||
(p = f(p, m, n, o, a[d + 2], 9, -51403784)),
|
||||
(o = f(o, p, m, n, a[d + 7], 14, 1735328473)),
|
||||
(n = f(n, o, p, m, a[d + 12], 20, -1926607734)),
|
||||
(m = g(m, n, o, p, a[d + 5], 4, -378558)),
|
||||
(p = g(p, m, n, o, a[d + 8], 11, -2022574463)),
|
||||
(o = g(o, p, m, n, a[d + 11], 16, 1839030562)),
|
||||
(n = g(n, o, p, m, a[d + 14], 23, -35309556)),
|
||||
(m = g(m, n, o, p, a[d + 1], 4, -1530992060)),
|
||||
(p = g(p, m, n, o, a[d + 4], 11, 1272893353)),
|
||||
(o = g(o, p, m, n, a[d + 7], 16, -155497632)),
|
||||
(n = g(n, o, p, m, a[d + 10], 23, -1094730640)),
|
||||
(m = g(m, n, o, p, a[d + 13], 4, 681279174)),
|
||||
(p = g(p, m, n, o, a[d], 11, -358537222)),
|
||||
(o = g(o, p, m, n, a[d + 3], 16, -722521979)),
|
||||
(n = g(n, o, p, m, a[d + 6], 23, 76029189)),
|
||||
(m = g(m, n, o, p, a[d + 9], 4, -640364487)),
|
||||
(p = g(p, m, n, o, a[d + 12], 11, -421815835)),
|
||||
(o = g(o, p, m, n, a[d + 15], 16, 530742520)),
|
||||
(n = g(n, o, p, m, a[d + 2], 23, -995338651)),
|
||||
(m = h(m, n, o, p, a[d], 6, -198630844)),
|
||||
(p = h(p, m, n, o, a[d + 7], 10, 1126891415)),
|
||||
(o = h(o, p, m, n, a[d + 14], 15, -1416354905)),
|
||||
(n = h(n, o, p, m, a[d + 5], 21, -57434055)),
|
||||
(m = h(m, n, o, p, a[d + 12], 6, 1700485571)),
|
||||
(p = h(p, m, n, o, a[d + 3], 10, -1894986606)),
|
||||
(o = h(o, p, m, n, a[d + 10], 15, -1051523)),
|
||||
(n = h(n, o, p, m, a[d + 1], 21, -2054922799)),
|
||||
(m = h(m, n, o, p, a[d + 8], 6, 1873313359)),
|
||||
(p = h(p, m, n, o, a[d + 15], 10, -30611744)),
|
||||
(o = h(o, p, m, n, a[d + 6], 15, -1560198380)),
|
||||
(n = h(n, o, p, m, a[d + 13], 21, 1309151649)),
|
||||
(m = h(m, n, o, p, a[d + 4], 6, -145523070)),
|
||||
(p = h(p, m, n, o, a[d + 11], 10, -1120210379)),
|
||||
(o = h(o, p, m, n, a[d + 2], 15, 718787259)),
|
||||
(n = h(n, o, p, m, a[d + 9], 21, -343485551)),
|
||||
(m = b(m, i)),
|
||||
(n = b(n, j)),
|
||||
(o = b(o, k)),
|
||||
(p = b(p, l));
|
||||
return [m, n, o, p];
|
||||
}
|
||||
function j(a) {
|
||||
var b,
|
||||
c = "";
|
||||
for (b = 0; b < 32 * a.length; b += 8)
|
||||
c += String.fromCharCode((a[b >> 5] >>> b % 32) & 255);
|
||||
return c;
|
||||
}
|
||||
function k(a) {
|
||||
var b,
|
||||
c = [];
|
||||
for (c[(a.length >> 2) - 1] = void 0, b = 0; b < c.length; b += 1) c[b] = 0;
|
||||
for (b = 0; b < 8 * a.length; b += 8)
|
||||
c[b >> 5] |= (255 & a.charCodeAt(b / 8)) << b % 32;
|
||||
return c;
|
||||
}
|
||||
function l(a) {
|
||||
return j(i(k(a), 8 * a.length));
|
||||
}
|
||||
function m(a, b) {
|
||||
var c,
|
||||
d,
|
||||
e = k(a),
|
||||
f = [],
|
||||
g = [];
|
||||
for (
|
||||
f[15] = g[15] = void 0, e.length > 16 && (e = i(e, 8 * a.length)), c = 0;
|
||||
16 > c;
|
||||
c += 1
|
||||
)
|
||||
(f[c] = 909522486 ^ e[c]), (g[c] = 1549556828 ^ e[c]);
|
||||
return (d = i(f.concat(k(b)), 512 + 8 * b.length)), j(i(g.concat(d), 640));
|
||||
}
|
||||
function n(a) {
|
||||
var b,
|
||||
c,
|
||||
d = "0123456789abcdef",
|
||||
e = "";
|
||||
for (c = 0; c < a.length; c += 1)
|
||||
(b = a.charCodeAt(c)), (e += d.charAt((b >>> 4) & 15) + d.charAt(15 & b));
|
||||
return e;
|
||||
}
|
||||
function o(a) {
|
||||
return unescape(encodeURIComponent(a));
|
||||
}
|
||||
function p(a) {
|
||||
return l(o(a));
|
||||
}
|
||||
function q(a) {
|
||||
return n(p(a));
|
||||
}
|
||||
function r(a, b) {
|
||||
return m(o(a), o(b));
|
||||
}
|
||||
function s(a, b) {
|
||||
return n(r(a, b));
|
||||
}
|
||||
function t(a, b, c) {
|
||||
return b ? (c ? r(b, a) : s(b, a)) : c ? p(a) : q(a);
|
||||
}
|
||||
"function" == typeof define && define.amd
|
||||
? define(function () {
|
||||
return t;
|
||||
})
|
||||
: (a.md5 = t);
|
||||
})(this);
|
@ -1,7 +1,6 @@
|
||||
package bootstrap
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"github.com/Xhofe/alist/conf"
|
||||
"github.com/Xhofe/alist/utils"
|
||||
log "github.com/sirupsen/logrus"
|
||||
@ -28,9 +27,18 @@ func InitConf() {
|
||||
log.Fatalf("reading config file error:%s", err.Error())
|
||||
}
|
||||
conf.Conf = new(conf.Config)
|
||||
err = json.Unmarshal(config, conf.Conf)
|
||||
err = utils.Json.Unmarshal(config, conf.Conf)
|
||||
if err != nil {
|
||||
log.Fatalf("load config error: %s", err.Error())
|
||||
}
|
||||
log.Debugf("config:%+v", conf.Conf)
|
||||
// update config.json struct
|
||||
confBody, err := utils.Json.Marshal(conf.Conf)
|
||||
if err != nil {
|
||||
log.Fatalf("marshal config error:%s", err.Error())
|
||||
}
|
||||
err = ioutil.WriteFile(conf.ConfigFile, confBody, 0777)
|
||||
if err != nil {
|
||||
log.Fatalf("update config struct error: %s", err.Error())
|
||||
}
|
||||
}
|
||||
|
@ -19,6 +19,7 @@ import (
|
||||
|
||||
func InitModel() {
|
||||
log.Infof("init model...")
|
||||
var err error
|
||||
databaseConfig := conf.Conf.Database
|
||||
newLogger := logger.New(
|
||||
log2.New(os.Stdout, "\r\n", log2.LstdFlags),
|
||||
@ -72,9 +73,13 @@ func InitModel() {
|
||||
log.Fatalf("not supported database type: %s", databaseConfig.Type)
|
||||
}
|
||||
log.Infof("auto migrate model...")
|
||||
err := conf.DB.AutoMigrate(&model.SettingItem{}, &model.Account{}, &model.Meta{})
|
||||
if databaseConfig.Type == "mysql" {
|
||||
err = conf.DB.Set("gorm:table_options", "ENGINE=InnoDB CHARSET=utf8mb4").
|
||||
AutoMigrate(&model.SettingItem{}, &model.Account{}, &model.Meta{})
|
||||
} else {
|
||||
err = conf.DB.AutoMigrate(&model.SettingItem{}, &model.Account{}, &model.Meta{})
|
||||
}
|
||||
if err != nil {
|
||||
log.Fatalf("failed to auto migrate")
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -131,6 +131,14 @@ func InitSettings() {
|
||||
Access: model.PRIVATE,
|
||||
Group: model.FRONT,
|
||||
},
|
||||
{
|
||||
Key: "home emoji",
|
||||
Value: "🏠",
|
||||
Type: "string",
|
||||
Description: "emoji in front of home in nav",
|
||||
Access: model.PUBLIC,
|
||||
Group: model.FRONT,
|
||||
},
|
||||
{
|
||||
Key: "animation",
|
||||
Value: "true",
|
||||
@ -195,6 +203,22 @@ func InitSettings() {
|
||||
Access: model.PRIVATE,
|
||||
Group: model.BACK,
|
||||
},
|
||||
{
|
||||
Key: "load type",
|
||||
Value: "all",
|
||||
Type: "select",
|
||||
Values: "all,load more,auto load more,pagination",
|
||||
Description: "Not recommended to choose to auto load more, it has bugs now",
|
||||
Access: model.PUBLIC,
|
||||
Group: model.FRONT,
|
||||
},
|
||||
{
|
||||
Key: "default page size",
|
||||
Value: "30",
|
||||
Type: "number",
|
||||
Access: model.PUBLIC,
|
||||
Group: model.FRONT,
|
||||
},
|
||||
}
|
||||
for i, _ := range settings {
|
||||
v := settings[i]
|
||||
@ -207,7 +231,7 @@ func InitSettings() {
|
||||
log.Fatalf("failed write setting: %s", err.Error())
|
||||
}
|
||||
} else {
|
||||
log.Fatal("can't get setting: %s", err.Error())
|
||||
log.Fatalf("can't get setting: %s", err.Error())
|
||||
}
|
||||
} else {
|
||||
//o.Version = conf.GitTag
|
||||
|
152
build.sh
152
build.sh
@ -1,17 +1,24 @@
|
||||
#!/bin/bash
|
||||
if [ "$1" == "web" ]; then
|
||||
git clone https://github.com/Xhofe/alist-web.git
|
||||
cd alist-web || exit
|
||||
|
||||
# 构建前端,在当前目录产生一个dist文件夹
|
||||
BUILD_WEB() {
|
||||
git clone https://github.com/alist-org/alist-web.git
|
||||
cd alist-web
|
||||
yarn
|
||||
yarn build
|
||||
mv dist/* ../public
|
||||
mv dist ..
|
||||
cd ..
|
||||
exit 0
|
||||
fi
|
||||
rm -rf alist-web
|
||||
}
|
||||
|
||||
go env -w GOPROXY=https://goproxy.cn,https://mirrors.aliyun.com/goproxy/,https://goproxy.io,direct
|
||||
CDN_WEB() {
|
||||
curl -L https://github.com/alist-org/alist-web/releases/latest/download/dist.tar.gz -o dist.tar.gz
|
||||
tar -zxvf dist.tar.gz
|
||||
rm -f dist.tar.gz
|
||||
}
|
||||
|
||||
if [ "$1" == "docker" ]; then
|
||||
# 在DOCKER中构建
|
||||
BUILD_DOCKER() {
|
||||
appName="alist"
|
||||
builtAt="$(date +'%F %T %z')"
|
||||
goVersion=$(go version | sed 's/go version //')
|
||||
@ -25,40 +32,20 @@ if [ "$1" == "docker" ]; then
|
||||
-X 'github.com/Xhofe/alist/conf.GitAuthor=$gitAuthor' \
|
||||
-X 'github.com/Xhofe/alist/conf.GitCommit=$gitCommit' \
|
||||
-X 'github.com/Xhofe/alist/conf.GitTag=$gitTag' \
|
||||
"
|
||||
go build -o ./bin/alist -ldflags="$ldflags" alist.go
|
||||
exit 0
|
||||
fi
|
||||
"
|
||||
go build -o ./bin/alist -ldflags="$ldflags" -tags=jsoniter alist.go
|
||||
}
|
||||
|
||||
cd alist-web || exit
|
||||
webCommit=$(git log --pretty=format:"%h" -1)
|
||||
echo "web commit id: $webCommit"
|
||||
yarn
|
||||
if [ "$1" == "release" ]; then
|
||||
yarn build --base="https://cdn.jsdelivr.net/gh/Xhofe/alist-web@cdn/v2/$webCommit"
|
||||
mv dist/assets ..
|
||||
mv dist/index.html ../alist/public
|
||||
# 构建local
|
||||
yarn build
|
||||
mv dist/index.html dist/local.html
|
||||
mv dist/* ../alist/public
|
||||
else
|
||||
yarn build
|
||||
mv dist/* ../alist/public
|
||||
fi
|
||||
cd ..
|
||||
|
||||
cd alist
|
||||
appName="alist"
|
||||
builtAt="$(date +'%F %T %z')"
|
||||
goVersion=$(go version | sed 's/go version //')
|
||||
gitAuthor=$(git show -s --format='format:%aN <%ae>' HEAD)
|
||||
gitCommit=$(git log --pretty=format:"%h" -1)
|
||||
gitTag=$(git describe --long --tags --dirty --always)
|
||||
|
||||
echo "build version: $gitTag"
|
||||
|
||||
ldflags="\
|
||||
BUILD() {
|
||||
cd alist
|
||||
appName="alist"
|
||||
builtAt="$(date +'%F %T %z')"
|
||||
goVersion=$(go version | sed 's/go version //')
|
||||
gitAuthor=$(git show -s --format='format:%aN <%ae>' HEAD)
|
||||
gitCommit=$(git log --pretty=format:"%h" -1)
|
||||
gitTag=$(git describe --long --tags --dirty --always)
|
||||
echo "build version: $gitTag"
|
||||
ldflags="\
|
||||
-w -s \
|
||||
-X 'github.com/Xhofe/alist/conf.BuiltAt=$builtAt' \
|
||||
-X 'github.com/Xhofe/alist/conf.GoVersion=$goVersion' \
|
||||
@ -67,44 +54,47 @@ ldflags="\
|
||||
-X 'github.com/Xhofe/alist/conf.GitTag=$gitTag' \
|
||||
"
|
||||
|
||||
if [ "$1" == "release" ]; then
|
||||
xgo -out alist -ldflags="$ldflags" .
|
||||
else
|
||||
xgo -targets=linux/amd64,windows/amd64 -out alist -ldflags="$ldflags" .
|
||||
fi
|
||||
mkdir "build"
|
||||
mv alist-* build
|
||||
cd build || exit
|
||||
upx -9 ./*
|
||||
find . -type f -print0 | xargs -0 md5sum > md5.txt
|
||||
cat md5.txt
|
||||
# compress file (release)
|
||||
if [ "$1" == "release" ]; then
|
||||
mkdir compress
|
||||
mv md5.txt compress
|
||||
for i in `find . -type f -name "$appName-linux-*"`
|
||||
do
|
||||
tar -czvf compress/"$i".tar.gz "$i"
|
||||
done
|
||||
for i in `find . -type f -name "$appName-darwin-*"`
|
||||
do
|
||||
tar -czvf compress/"$i".tar.gz "$i"
|
||||
done
|
||||
for i in `find . -type f -name "$appName-windows-*"`
|
||||
do
|
||||
zip compress/$(echo $i | sed 's/\.[^.]*$//').zip "$i"
|
||||
done
|
||||
fi
|
||||
cd ../..
|
||||
if [ "$1" == "release" ]; then
|
||||
xgo -out "$appName" -ldflags="$ldflags" -tags=jsoniter .
|
||||
else
|
||||
xgo -targets=linux/amd64,windows/amd64 -out alist -ldflags="$ldflags" -tags=jsoniter .
|
||||
fi
|
||||
mkdir "build"
|
||||
mv alist-* build
|
||||
cd build
|
||||
upx -9 ./*
|
||||
find . -type f -print0 | xargs -0 md5sum >md5.txt
|
||||
cat md5.txt
|
||||
cd ../..
|
||||
}
|
||||
|
||||
if [ "$1" == "release" ]; then
|
||||
cd alist-web
|
||||
git checkout cdn
|
||||
mkdir "v2/$webCommit"
|
||||
mv ../assets/ v2/$webCommit
|
||||
git add .
|
||||
git config --local user.email "i@nn.ci"
|
||||
git config --local user.name "Xhofe"
|
||||
git commit --allow-empty -m "upload $webCommit assets files" -a
|
||||
cd ..
|
||||
fi
|
||||
RELEASE() {
|
||||
cd alist/build
|
||||
mkdir compress
|
||||
mv md5.txt compress
|
||||
for i in $(find . -type f -name "$appName-linux-*"); do
|
||||
tar -czvf compress/"$i".tar.gz "$i"
|
||||
done
|
||||
for i in $(find . -type f -name "$appName-darwin-*"); do
|
||||
tar -czvf compress/"$i".tar.gz "$i"
|
||||
done
|
||||
for i in $(find . -type f -name "$appName-windows-*"); do
|
||||
zip compress/$(echo $i | sed 's/\.[^.]*$//').zip "$i"
|
||||
done
|
||||
cd ../..
|
||||
}
|
||||
|
||||
if [ "$1" = "web" ]; then
|
||||
BUILD_WEB
|
||||
elif [ "$1" = "cdn" ]; then
|
||||
CDN_WEB
|
||||
elif [ "$1" = "docker" ]; then
|
||||
BUILD_DOCKER
|
||||
elif [ "$1" = "build" ]; then
|
||||
BUILD build
|
||||
elif [ "$1" = "release" ]; then
|
||||
BUILD release
|
||||
RELEASE
|
||||
else
|
||||
echo -e "${RED_COLOR} 错误的命令${RES}"
|
||||
fi
|
||||
|
61
conf/var.go
61
conf/var.go
@ -5,6 +5,7 @@ import (
|
||||
"github.com/eko/gocache/v2/cache"
|
||||
"github.com/robfig/cron/v3"
|
||||
"gorm.io/gorm"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
var (
|
||||
@ -33,21 +34,63 @@ var (
|
||||
"js", "md", "json", "conf", "ini", "vue", "php", "py", "bat", "gitignore", "yml",
|
||||
"go", "sh", "c", "cpp", "h", "hpp", "tsx", "vtt", "srt", "ass"}
|
||||
OfficeTypes = []string{"doc", "docx", "xls", "xlsx", "ppt", "pptx", "pdf"}
|
||||
VideoTypes = []string{"mp4", "mkv", "avi", "mov", "rmvb", "webm"}
|
||||
VideoTypes = []string{"mp4", "mkv", "avi", "mov", "rmvb", "webm", "flv"}
|
||||
AudioTypes = []string{"mp3", "flac", "ogg", "m4a", "wav"}
|
||||
ImageTypes = []string{"jpg", "tiff", "jpeg", "png", "gif", "bmp", "svg", "ico"}
|
||||
)
|
||||
|
||||
// settings
|
||||
var settingsMap = make(map[string]string, 0)
|
||||
|
||||
func Set(key string, value string) {
|
||||
settingsMap[key] = value
|
||||
}
|
||||
|
||||
func GetStr(key string) string {
|
||||
value, ok := settingsMap[key]
|
||||
if !ok {
|
||||
return ""
|
||||
}
|
||||
return value
|
||||
}
|
||||
|
||||
func GetBool(key string) bool {
|
||||
value, ok := settingsMap[key]
|
||||
if !ok {
|
||||
return false
|
||||
}
|
||||
return value == "true"
|
||||
}
|
||||
|
||||
func GetInt(key string, defaultV int) int {
|
||||
value, ok := settingsMap[key]
|
||||
if !ok {
|
||||
return defaultV
|
||||
}
|
||||
v, err := strconv.Atoi(value)
|
||||
if err != nil {
|
||||
return defaultV
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
var (
|
||||
LoadSettings = []string{
|
||||
"check parent folder", "check down link", "WebDAV username", "WebDAV password",
|
||||
"Visitor WebDAV username", "Visitor WebDAV password",
|
||||
"default page size", "load type",
|
||||
}
|
||||
)
|
||||
|
||||
var (
|
||||
RawIndexHtml string
|
||||
ManageHtml string
|
||||
IndexHtml string
|
||||
CheckParent bool
|
||||
CheckDown bool
|
||||
Token string
|
||||
|
||||
Token string
|
||||
DavUsername string
|
||||
DavPassword string
|
||||
VisitorDavUsername string
|
||||
VisitorDavPassword string
|
||||
//CheckParent bool
|
||||
//CheckDown bool
|
||||
//DavUsername string
|
||||
//DavPassword string
|
||||
//VisitorDavUsername string
|
||||
//VisitorDavPassword string
|
||||
)
|
||||
|
@ -1,8 +1,6 @@
|
||||
package _23
|
||||
|
||||
import (
|
||||
"crypto/hmac"
|
||||
"crypto/sha256"
|
||||
"errors"
|
||||
"fmt"
|
||||
"github.com/Xhofe/alist/conf"
|
||||
@ -12,7 +10,6 @@ import (
|
||||
"github.com/go-resty/resty/v2"
|
||||
jsoniter "github.com/json-iterator/go"
|
||||
log "github.com/sirupsen/logrus"
|
||||
"math/rand"
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
"time"
|
||||
@ -55,6 +52,18 @@ type Pan123DownResp struct {
|
||||
} `json:"data"`
|
||||
}
|
||||
|
||||
type UploadResp struct {
|
||||
BaseResp
|
||||
Data struct {
|
||||
AccessKeyId string `json:"AccessKeyId"`
|
||||
Bucket string `json:"Bucket"`
|
||||
Key string `json:"Key"`
|
||||
SecretAccessKey string `json:"SecretAccessKey"`
|
||||
SessionToken string `json:"SessionToken"`
|
||||
FileId int64 `json:"FileId"`
|
||||
} `json:"data"`
|
||||
}
|
||||
|
||||
func (driver Pan123) Login(account *model.Account) error {
|
||||
url := "https://www.123pan.com/api/user/sign_in"
|
||||
if account.APIProxyUrl != "" {
|
||||
@ -205,27 +214,16 @@ func (driver Pan123) GetFile(path string, account *model.Account) (*Pan123File,
|
||||
return nil, base.ErrPathNotFound
|
||||
}
|
||||
|
||||
func RandStr(length int) string {
|
||||
str := "123456789abcdefghijklmnopqrstuvwxyz"
|
||||
bytes := []byte(str)
|
||||
var result []byte
|
||||
rand.Seed(time.Now().UnixNano() + int64(rand.Intn(100)))
|
||||
for i := 0; i < length; i++ {
|
||||
result = append(result, bytes[rand.Intn(len(bytes))])
|
||||
}
|
||||
return string(result)
|
||||
}
|
||||
|
||||
func HMAC(message string, secret string) string {
|
||||
key := []byte(secret)
|
||||
h := hmac.New(sha256.New, key)
|
||||
h.Write([]byte(message))
|
||||
// fmt.Println(h.Sum(nil))
|
||||
//sha := hex.EncodeToString(h.Sum(nil))
|
||||
// fmt.Println(sha)
|
||||
//return sha
|
||||
return string(h.Sum(nil))
|
||||
}
|
||||
//func HMAC(message string, secret string) string {
|
||||
// key := []byte(secret)
|
||||
// h := hmac.New(sha256.New, key)
|
||||
// h.Write([]byte(message))
|
||||
// // fmt.Println(h.Sum(nil))
|
||||
// //sha := hex.EncodeToString(h.Sum(nil))
|
||||
// // fmt.Println(sha)
|
||||
// //return sha
|
||||
// return string(h.Sum(nil))
|
||||
//}
|
||||
|
||||
func init() {
|
||||
base.RegisterDriver(&Pan123{})
|
||||
|
@ -1,21 +1,20 @@
|
||||
package _23
|
||||
|
||||
import (
|
||||
"encoding/hex"
|
||||
"encoding/xml"
|
||||
"fmt"
|
||||
"github.com/Xhofe/alist/conf"
|
||||
"github.com/Xhofe/alist/drivers/base"
|
||||
"github.com/Xhofe/alist/model"
|
||||
"github.com/Xhofe/alist/utils"
|
||||
"github.com/aws/aws-sdk-go/aws"
|
||||
"github.com/aws/aws-sdk-go/aws/credentials"
|
||||
"github.com/aws/aws-sdk-go/aws/session"
|
||||
"github.com/aws/aws-sdk-go/service/s3/s3manager"
|
||||
"github.com/gin-gonic/gin"
|
||||
jsoniter "github.com/json-iterator/go"
|
||||
log "github.com/sirupsen/logrus"
|
||||
"net/url"
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
type Pan123 struct{}
|
||||
@ -218,50 +217,46 @@ func (driver Pan123) MakeDir(path string, account *model.Account) error {
|
||||
}
|
||||
_, err = driver.Request("https://www.123pan.com/api/file/upload_request",
|
||||
base.Post, nil, nil, &data, nil, false, account)
|
||||
//_, err = driver.Post("https://www.123pan.com/api/file/upload_request", data, account)
|
||||
if err == nil {
|
||||
_ = base.DeleteCache(dir, account)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func (driver Pan123) Move(src string, dst string, account *model.Account) error {
|
||||
srcDir, _ := filepath.Split(src)
|
||||
dstDir, dstName := filepath.Split(dst)
|
||||
dstDir, _ := filepath.Split(dst)
|
||||
srcFile, err := driver.File(src, account)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
fileId, _ := strconv.Atoi(srcFile.Id)
|
||||
// rename
|
||||
if srcDir == dstDir {
|
||||
data := base.Json{
|
||||
"driveId": 0,
|
||||
"fileId": fileId,
|
||||
"fileName": dstName,
|
||||
}
|
||||
_, err = driver.Request("https://www.123pan.com/api/file/rename",
|
||||
base.Post, nil, nil, &data, nil, false, account)
|
||||
//_, err = driver.Post("https://www.123pan.com/api/file/rename", data, account)
|
||||
} else {
|
||||
// move
|
||||
dstDirFile, err := driver.File(dstDir, account)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
parentFileId, _ := strconv.Atoi(dstDirFile.Id)
|
||||
data := base.Json{
|
||||
"fileId": fileId,
|
||||
"parentFileId": parentFileId,
|
||||
}
|
||||
_, err = driver.Request("https://www.123pan.com/api/file/mod_pid",
|
||||
base.Post, nil, nil, &data, nil, false, account)
|
||||
//_, err = driver.Post("https://www.123pan.com/api/file/mod_pid", data, account)
|
||||
}
|
||||
|
||||
dstDirFile, err := driver.File(dstDir, account)
|
||||
if err != nil {
|
||||
_ = base.DeleteCache(srcDir, account)
|
||||
_ = base.DeleteCache(dstDir, account)
|
||||
return err
|
||||
}
|
||||
parentFileId, _ := strconv.Atoi(dstDirFile.Id)
|
||||
data := base.Json{
|
||||
"fileId": fileId,
|
||||
"parentFileId": parentFileId,
|
||||
}
|
||||
_, err = driver.Request("https://www.123pan.com/api/file/mod_pid",
|
||||
base.Post, nil, nil, &data, nil, false, account)
|
||||
return err
|
||||
}
|
||||
|
||||
func (driver Pan123) Rename(src string, dst string, account *model.Account) error {
|
||||
_, dstName := filepath.Split(dst)
|
||||
srcFile, err := driver.File(src, account)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
fileId, _ := strconv.Atoi(srcFile.Id)
|
||||
|
||||
data := base.Json{
|
||||
"driveId": 0,
|
||||
"fileId": fileId,
|
||||
"fileName": dstName,
|
||||
}
|
||||
_, err = driver.Request("https://www.123pan.com/api/file/rename",
|
||||
base.Post, nil, nil, &data, nil, false, account)
|
||||
return err
|
||||
}
|
||||
|
||||
@ -281,23 +276,13 @@ func (driver Pan123) Delete(path string, account *model.Account) error {
|
||||
}
|
||||
_, err = driver.Request("https://www.123pan.com/api/file/trash",
|
||||
base.Post, nil, nil, &data, nil, false, account)
|
||||
//_, err = driver.Post("https://www.123pan.com/api/file/trash", data, account)
|
||||
if err == nil {
|
||||
_ = base.DeleteCache(utils.Dir(path), account)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
type UploadResp struct {
|
||||
XMLName xml.Name `xml:"InitiateMultipartUploadResult"`
|
||||
Bucket string `xml:"Bucket"`
|
||||
Key string `xml:"Key"`
|
||||
UploadId string `xml:"UploadId"`
|
||||
}
|
||||
|
||||
// TODO unfinished
|
||||
func (driver Pan123) Upload(file *model.FileStream, account *model.Account) error {
|
||||
return base.ErrNotImplement
|
||||
if file == nil {
|
||||
return base.ErrEmptyFile
|
||||
}
|
||||
parentFile, err := driver.File(file.ParentPath, account)
|
||||
if err != nil {
|
||||
return err
|
||||
@ -309,47 +294,107 @@ func (driver Pan123) Upload(file *model.FileStream, account *model.Account) erro
|
||||
data := base.Json{
|
||||
"driveId": 0,
|
||||
"duplicate": true,
|
||||
"etag": RandStr(32), //maybe file's md5
|
||||
"etag": "836aae6cac845e17fce51919594737d0", //maybe file's md5
|
||||
"fileName": file.GetFileName(),
|
||||
"parentFileId": parentFileId,
|
||||
"size": file.GetSize(),
|
||||
"type": 0,
|
||||
}
|
||||
res, err := driver.Request("https://www.123pan.com/api/file/upload_request",
|
||||
base.Post, nil, nil, &data, nil, false, account)
|
||||
var resp UploadResp
|
||||
_, err = driver.Request("https://www.123pan.com/api/file/upload_request",
|
||||
base.Post, nil, nil, &data, &resp, false, account)
|
||||
//res, err := driver.Post("https://www.123pan.com/api/file/upload_request", data, account)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
baseUrl := fmt.Sprintf("https://file.123pan.com/%s/%s", jsoniter.Get(res, "data.Bucket").ToString(), jsoniter.Get(res, "data.Key").ToString())
|
||||
var resp UploadResp
|
||||
kSecret := jsoniter.Get(res, "data.SecretAccessKey").ToString()
|
||||
nowTimeStr := time.Now().String()
|
||||
Date := strings.ReplaceAll(strings.Split(nowTimeStr, "T")[0], "-", "")
|
||||
|
||||
StringToSign := fmt.Sprintf("%s\n%s\n%s\n%s",
|
||||
"AWS4-HMAC-SHA256",
|
||||
nowTimeStr,
|
||||
fmt.Sprintf("%s/us-east-1/s3/aws4_request", Date),
|
||||
)
|
||||
|
||||
kDate := HMAC("AWS4"+kSecret, Date)
|
||||
kRegion := HMAC(kDate, "us-east-1")
|
||||
kService := HMAC(kRegion, "s3")
|
||||
kSigning := HMAC(kService, "aws4_request")
|
||||
_, err = base.RestyClient.R().SetResult(&resp).SetHeaders(map[string]string{
|
||||
"Authorization": fmt.Sprintf("AWS4-HMAC-SHA256 Credential=%s/%s/us-east-1/s3/aws4_request, SignedHeaders=host;x-amz-content-sha256;x-amz-date;x-amz-security-token;x-amz-user-agent, Signature=%s",
|
||||
jsoniter.Get(res, "data.AccessKeyId"),
|
||||
Date,
|
||||
hex.EncodeToString([]byte(HMAC(StringToSign, kSigning)))),
|
||||
"X-Amz-Content-Sha256": "UNSIGNED-PAYLOAD",
|
||||
"X-Amz-Date": nowTimeStr,
|
||||
"x-amz-security-token": jsoniter.Get(res, "data.SessionToken").ToString(),
|
||||
}).Post(fmt.Sprintf("%s?uploads", baseUrl))
|
||||
cfg := &aws.Config{
|
||||
Credentials: credentials.NewStaticCredentials(resp.Data.AccessKeyId, resp.Data.SecretAccessKey, resp.Data.SessionToken),
|
||||
Region: aws.String("123pan"),
|
||||
Endpoint: aws.String("file.123pan.com"),
|
||||
S3ForcePathStyle: aws.Bool(true),
|
||||
}
|
||||
s, err := session.NewSession(cfg)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return base.ErrNotImplement
|
||||
uploader := s3manager.NewUploader(s)
|
||||
input := &s3manager.UploadInput{
|
||||
Bucket: &resp.Data.Bucket,
|
||||
Key: &resp.Data.Key,
|
||||
Body: file,
|
||||
}
|
||||
_, err = uploader.Upload(input)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, err = driver.Request("https://www.123pan.com/api/file/upload_complete", base.Post, nil, nil, &base.Json{
|
||||
"fileId": resp.Data.FileId,
|
||||
}, nil, false, account)
|
||||
return err
|
||||
}
|
||||
|
||||
//type UploadResp struct {
|
||||
// XMLName xml.Name `xml:"InitiateMultipartUploadResult"`
|
||||
// Bucket string `xml:"Bucket"`
|
||||
// Key string `xml:"Key"`
|
||||
// UploadId string `xml:"UploadId"`
|
||||
//}
|
||||
|
||||
// TODO unfinished
|
||||
//func (driver Pan123) Upload(file *model.FileStream, account *model.Account) error {
|
||||
// return base.ErrNotImplement
|
||||
// parentFile, err := driver.File(file.ParentPath, account)
|
||||
// if err != nil {
|
||||
// return err
|
||||
// }
|
||||
// if !parentFile.IsDir() {
|
||||
// return base.ErrNotFolder
|
||||
// }
|
||||
// parentFileId, _ := strconv.Atoi(parentFile.Id)
|
||||
// data := base.Json{
|
||||
// "driveId": 0,
|
||||
// "duplicate": true,
|
||||
// "etag": RandStr(32), //maybe file's md5
|
||||
// "fileName": file.GetFileName(),
|
||||
// "parentFileId": parentFileId,
|
||||
// "size": file.GetSize(),
|
||||
// "type": 0,
|
||||
// }
|
||||
// res, err := driver.Request("https://www.123pan.com/api/file/upload_request",
|
||||
// base.Post, nil, nil, &data, nil, false, account)
|
||||
// //res, err := driver.Post("https://www.123pan.com/api/file/upload_request", data, account)
|
||||
// if err != nil {
|
||||
// return err
|
||||
// }
|
||||
// baseUrl := fmt.Sprintf("https://file.123pan.com/%s/%s", jsoniter.Get(res, "data.Bucket").ToString(), jsoniter.Get(res, "data.Key").ToString())
|
||||
// var resp UploadResp
|
||||
// kSecret := jsoniter.Get(res, "data.SecretAccessKey").ToString()
|
||||
// nowTimeStr := time.Now().String()
|
||||
// Date := strings.ReplaceAll(strings.Split(nowTimeStr, "T")[0], "-", "")
|
||||
//
|
||||
// StringToSign := fmt.Sprintf("%s\n%s\n%s\n%s",
|
||||
// "AWS4-HMAC-SHA256",
|
||||
// nowTimeStr,
|
||||
// fmt.Sprintf("%s/us-east-1/s3/aws4_request", Date),
|
||||
// )
|
||||
//
|
||||
// kDate := HMAC("AWS4"+kSecret, Date)
|
||||
// kRegion := HMAC(kDate, "us-east-1")
|
||||
// kService := HMAC(kRegion, "s3")
|
||||
// kSigning := HMAC(kService, "aws4_request")
|
||||
// _, err = base.RestyClient.R().SetResult(&resp).SetHeaders(map[string]string{
|
||||
// "Authorization": fmt.Sprintf("AWS4-HMAC-SHA256 Credential=%s/%s/us-east-1/s3/aws4_request, SignedHeaders=host;x-amz-content-sha256;x-amz-date;x-amz-security-token;x-amz-user-agent, Signature=%s",
|
||||
// jsoniter.Get(res, "data.AccessKeyId"),
|
||||
// Date,
|
||||
// hex.EncodeToString([]byte(HMAC(StringToSign, kSigning)))),
|
||||
// "X-Amz-Content-Sha256": "UNSIGNED-PAYLOAD",
|
||||
// "X-Amz-Date": nowTimeStr,
|
||||
// "x-amz-security-token": jsoniter.Get(res, "data.SessionToken").ToString(),
|
||||
// }).Post(fmt.Sprintf("%s?uploads", baseUrl))
|
||||
// if err != nil {
|
||||
// return err
|
||||
// }
|
||||
// return base.ErrNotImplement
|
||||
//}
|
||||
|
||||
var _ base.Driver = (*Pan123)(nil)
|
||||
|
175
drivers/139/139.go
Normal file
175
drivers/139/139.go
Normal file
@ -0,0 +1,175 @@
|
||||
package _39
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"github.com/Xhofe/alist/conf"
|
||||
"github.com/Xhofe/alist/drivers/base"
|
||||
"github.com/Xhofe/alist/model"
|
||||
"github.com/Xhofe/alist/utils"
|
||||
"github.com/go-resty/resty/v2"
|
||||
jsoniter "github.com/json-iterator/go"
|
||||
log "github.com/sirupsen/logrus"
|
||||
"path"
|
||||
"time"
|
||||
)
|
||||
|
||||
func (driver Cloud139) Request(pathname string, method int, headers, query, form map[string]string, data interface{}, resp interface{}, account *model.Account) ([]byte, error) {
|
||||
url := "https://yun.139.com" + pathname
|
||||
req := base.RestyClient.R()
|
||||
randStr := randomStr(16)
|
||||
ts := time.Now().Format("2006-01-02 15:04:05")
|
||||
log.Debugf("%+v", data)
|
||||
body, err := utils.Json.Marshal(data)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
sign := calSign(string(body), ts, randStr)
|
||||
svcType := "1"
|
||||
if isFamily(account) {
|
||||
svcType = "2"
|
||||
}
|
||||
req.SetHeaders(map[string]string{
|
||||
"Accept": "application/json, text/plain, */*",
|
||||
"CMS-DEVICE": "default",
|
||||
"Cookie": account.AccessToken,
|
||||
"mcloud-channel": "1000101",
|
||||
"mcloud-client": "10701",
|
||||
//"mcloud-route": "001",
|
||||
"mcloud-sign": fmt.Sprintf("%s,%s,%s", ts, randStr, sign),
|
||||
//"mcloud-skey":"",
|
||||
"mcloud-version": "6.6.0",
|
||||
"Origin": "https://yun.139.com",
|
||||
"Referer": "https://yun.139.com/w/",
|
||||
"x-DeviceInfo": "||9|6.6.0|chrome|95.0.4638.69|uwIy75obnsRPIwlJSd7D9GhUvFwG96ce||macos 10.15.2||zh-CN|||",
|
||||
"x-huawei-channelSrc": "10000034",
|
||||
"x-inner-ntwk": "2",
|
||||
"x-m4c-caller": "PC",
|
||||
"x-m4c-src": "10002",
|
||||
"x-SvcType": svcType,
|
||||
})
|
||||
if headers != nil {
|
||||
req.SetHeaders(headers)
|
||||
}
|
||||
if query != nil {
|
||||
req.SetQueryParams(query)
|
||||
}
|
||||
if form != nil {
|
||||
req.SetFormData(form)
|
||||
}
|
||||
if data != nil {
|
||||
req.SetBody(data)
|
||||
}
|
||||
var e BaseResp
|
||||
//var err error
|
||||
var res *resty.Response
|
||||
req.SetResult(&e)
|
||||
switch method {
|
||||
case base.Get:
|
||||
res, err = req.Get(url)
|
||||
case base.Post:
|
||||
res, err = req.Post(url)
|
||||
case base.Delete:
|
||||
res, err = req.Delete(url)
|
||||
case base.Patch:
|
||||
res, err = req.Patch(url)
|
||||
case base.Put:
|
||||
res, err = req.Put(url)
|
||||
default:
|
||||
return nil, base.ErrNotSupport
|
||||
}
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
log.Debugln(res.String())
|
||||
if !e.Success {
|
||||
return nil, errors.New(e.Message)
|
||||
}
|
||||
if resp != nil {
|
||||
err = utils.Json.Unmarshal(res.Body(), resp)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
return res.Body(), nil
|
||||
}
|
||||
|
||||
func (driver Cloud139) Post(pathname string, data interface{}, resp interface{}, account *model.Account) ([]byte, error) {
|
||||
return driver.Request(pathname, base.Post, nil, nil, nil, data, resp, account)
|
||||
}
|
||||
|
||||
func (driver Cloud139) GetFiles(catalogID string, account *model.Account) ([]model.File, error) {
|
||||
start := 0
|
||||
limit := 100
|
||||
files := make([]model.File, 0)
|
||||
for {
|
||||
data := base.Json{
|
||||
"catalogID": catalogID,
|
||||
"sortDirection": 1,
|
||||
"startNumber": start + 1,
|
||||
"endNumber": start + limit,
|
||||
"filterType": 0,
|
||||
"catalogSortType": 0,
|
||||
"contentSortType": 0,
|
||||
"commonAccountInfo": base.Json{
|
||||
"account": account.Username,
|
||||
"accountType": 1,
|
||||
},
|
||||
}
|
||||
var resp GetDiskResp
|
||||
_, err := driver.Post("/orchestration/personalCloud/catalog/v1.0/getDisk", data, &resp, account)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
for _, catalog := range resp.Data.GetDiskResult.CatalogList {
|
||||
f := model.File{
|
||||
Id: catalog.CatalogID,
|
||||
Name: catalog.CatalogName,
|
||||
Size: 0,
|
||||
Type: conf.FOLDER,
|
||||
Driver: driver.Config().Name,
|
||||
UpdatedAt: getTime(catalog.UpdateTime),
|
||||
}
|
||||
files = append(files, f)
|
||||
}
|
||||
for _, content := range resp.Data.GetDiskResult.ContentList {
|
||||
f := model.File{
|
||||
Id: content.ContentID,
|
||||
Name: content.ContentName,
|
||||
Size: int64(content.ContentSize),
|
||||
Type: utils.GetFileType(path.Ext(content.ContentName)),
|
||||
Driver: driver.Config().Name,
|
||||
UpdatedAt: getTime(content.UpdateTime),
|
||||
Thumbnail: content.ThumbnailURL,
|
||||
//Thumbnail: content.BigthumbnailURL,
|
||||
}
|
||||
files = append(files, f)
|
||||
}
|
||||
if start+limit >= resp.Data.GetDiskResult.NodeCount {
|
||||
break
|
||||
}
|
||||
start += limit
|
||||
}
|
||||
return files, nil
|
||||
}
|
||||
|
||||
func (driver Cloud139) GetLink(contentId string, account *model.Account) (string, error) {
|
||||
data := base.Json{
|
||||
"appName": "",
|
||||
"contentID": contentId,
|
||||
"commonAccountInfo": base.Json{
|
||||
"account": "18627147660",
|
||||
"accountType": 1,
|
||||
},
|
||||
}
|
||||
res, err := driver.Post("/orchestration/personalCloud/uploadAndDownload/v1.0/downloadRequest",
|
||||
data, nil, account)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
return jsoniter.Get(res, "data", "downloadURL").ToString(), nil
|
||||
}
|
||||
|
||||
func init() {
|
||||
base.RegisterDriver(&Cloud139{})
|
||||
}
|
449
drivers/139/driver.go
Normal file
449
drivers/139/driver.go
Normal file
@ -0,0 +1,449 @@
|
||||
package _39
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"github.com/Xhofe/alist/conf"
|
||||
"github.com/Xhofe/alist/drivers/base"
|
||||
"github.com/Xhofe/alist/model"
|
||||
"github.com/Xhofe/alist/utils"
|
||||
"github.com/gin-gonic/gin"
|
||||
log "github.com/sirupsen/logrus"
|
||||
"io"
|
||||
"math"
|
||||
"net/http"
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
type Cloud139 struct{}
|
||||
|
||||
func (driver Cloud139) Config() base.DriverConfig {
|
||||
return base.DriverConfig{
|
||||
Name: "139Yun",
|
||||
LocalSort: true,
|
||||
}
|
||||
}
|
||||
|
||||
func (driver Cloud139) Items() []base.Item {
|
||||
return []base.Item{
|
||||
{
|
||||
Name: "username",
|
||||
Label: "phone",
|
||||
Type: base.TypeString,
|
||||
Required: true,
|
||||
Description: "phone number",
|
||||
},
|
||||
{
|
||||
Name: "access_token",
|
||||
Label: "Cookie",
|
||||
Type: base.TypeString,
|
||||
Required: true,
|
||||
Description: "Unknown expiration time",
|
||||
},
|
||||
{
|
||||
Name: "internal_type",
|
||||
Label: "139yun type",
|
||||
Type: base.TypeSelect,
|
||||
Required: true,
|
||||
Values: "Personal,Family",
|
||||
},
|
||||
{
|
||||
Name: "root_folder",
|
||||
Label: "root folder file_id",
|
||||
Type: base.TypeString,
|
||||
Required: true,
|
||||
},
|
||||
{
|
||||
Name: "site_id",
|
||||
Label: "cloud_id",
|
||||
Type: base.TypeString,
|
||||
Required: false,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func (driver Cloud139) Save(account *model.Account, old *model.Account) error {
|
||||
_, err := driver.Request("/orchestration/personalCloud/user/v1.0/qryUserExternInfo", base.Post, nil, nil, nil, base.Json{
|
||||
"qryUserExternInfoReq": base.Json{
|
||||
"commonAccountInfo": base.Json{
|
||||
"account": account.Username,
|
||||
"accountType": 1,
|
||||
},
|
||||
},
|
||||
}, nil, account)
|
||||
return err
|
||||
}
|
||||
|
||||
func (driver Cloud139) File(path string, account *model.Account) (*model.File, error) {
|
||||
path = utils.ParsePath(path)
|
||||
if path == "/" {
|
||||
return &model.File{
|
||||
Id: account.RootFolder,
|
||||
Name: account.Name,
|
||||
Size: 0,
|
||||
Type: conf.FOLDER,
|
||||
Driver: driver.Config().Name,
|
||||
UpdatedAt: account.UpdatedAt,
|
||||
}, nil
|
||||
}
|
||||
dir, name := filepath.Split(path)
|
||||
files, err := driver.Files(dir, account)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
for _, file := range files {
|
||||
if file.Name == name {
|
||||
return &file, nil
|
||||
}
|
||||
}
|
||||
return nil, base.ErrPathNotFound
|
||||
}
|
||||
|
||||
func (driver Cloud139) Files(path string, account *model.Account) ([]model.File, error) {
|
||||
path = utils.ParsePath(path)
|
||||
var files []model.File
|
||||
cache, err := base.GetCache(path, account)
|
||||
if err == nil {
|
||||
files, _ = cache.([]model.File)
|
||||
} else {
|
||||
file, err := driver.File(path, account)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if isFamily(account) {
|
||||
files, err = driver.familyGetFiles(file.Id, account)
|
||||
} else {
|
||||
files, err = driver.GetFiles(file.Id, account)
|
||||
}
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if len(files) > 0 {
|
||||
_ = base.SetCache(path, files, account)
|
||||
}
|
||||
}
|
||||
return files, nil
|
||||
}
|
||||
|
||||
func (driver Cloud139) Link(args base.Args, account *model.Account) (*base.Link, error) {
|
||||
file, err := driver.File(args.Path, account)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
u, err := driver.GetLink(file.Id, account)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &base.Link{Url: u}, nil
|
||||
}
|
||||
|
||||
func (driver Cloud139) Path(path string, account *model.Account) (*model.File, []model.File, error) {
|
||||
path = utils.ParsePath(path)
|
||||
log.Debugf("139 path: %s", path)
|
||||
file, err := driver.File(path, account)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
if !file.IsDir() {
|
||||
return file, nil, nil
|
||||
}
|
||||
files, err := driver.Files(path, account)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
return nil, files, nil
|
||||
}
|
||||
|
||||
func (driver Cloud139) Proxy(c *gin.Context, account *model.Account) {
|
||||
|
||||
}
|
||||
|
||||
func (driver Cloud139) Preview(path string, account *model.Account) (interface{}, error) {
|
||||
return nil, base.ErrNotSupport
|
||||
}
|
||||
|
||||
func (driver Cloud139) MakeDir(path string, account *model.Account) error {
|
||||
parentFile, err := driver.File(utils.Dir(path), account)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
data := base.Json{
|
||||
"createCatalogExtReq": base.Json{
|
||||
"parentCatalogID": parentFile.Id,
|
||||
"newCatalogName": utils.Base(path),
|
||||
"commonAccountInfo": base.Json{
|
||||
"account": account.Username,
|
||||
"accountType": 1,
|
||||
},
|
||||
},
|
||||
}
|
||||
pathname := "/orchestration/personalCloud/catalog/v1.0/createCatalogExt"
|
||||
if isFamily(account) {
|
||||
data = base.Json{
|
||||
"cloudID": account.SiteId,
|
||||
"commonAccountInfo": base.Json{
|
||||
"account": account.Username,
|
||||
"accountType": 1,
|
||||
},
|
||||
"docLibName": utils.Base(path),
|
||||
}
|
||||
pathname = "/orchestration/familyCloud/cloudCatalog/v1.0/createCloudDoc"
|
||||
}
|
||||
_, err = driver.Post(pathname,
|
||||
data, nil, account)
|
||||
return err
|
||||
}
|
||||
|
||||
func (driver Cloud139) Move(src string, dst string, account *model.Account) error {
|
||||
if isFamily(account) {
|
||||
return base.ErrNotSupport
|
||||
}
|
||||
srcFile, err := driver.File(src, account)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
dstParentFile, err := driver.File(utils.Dir(dst), account)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
var contentInfoList []string
|
||||
var catalogInfoList []string
|
||||
if srcFile.IsDir() {
|
||||
catalogInfoList = append(catalogInfoList, srcFile.Id)
|
||||
} else {
|
||||
contentInfoList = append(contentInfoList, srcFile.Id)
|
||||
}
|
||||
data := base.Json{
|
||||
"createBatchOprTaskReq": base.Json{
|
||||
"taskType": 3,
|
||||
"actionType": "304",
|
||||
"taskInfo": base.Json{
|
||||
"contentInfoList": contentInfoList,
|
||||
"catalogInfoList": catalogInfoList,
|
||||
"newCatalogID": dstParentFile.Id,
|
||||
},
|
||||
"commonAccountInfo": base.Json{
|
||||
"account": "18627147660",
|
||||
"accountType": 1,
|
||||
},
|
||||
},
|
||||
}
|
||||
pathname := "/orchestration/personalCloud/batchOprTask/v1.0/createBatchOprTask"
|
||||
_, err = driver.Post(pathname, data, nil, account)
|
||||
return err
|
||||
}
|
||||
|
||||
func (driver Cloud139) Rename(src string, dst string, account *model.Account) error {
|
||||
if isFamily(account) {
|
||||
return base.ErrNotSupport
|
||||
}
|
||||
srcFile, err := driver.File(src, account)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
var data base.Json
|
||||
var pathname string
|
||||
if srcFile.IsDir() {
|
||||
data = base.Json{
|
||||
"catalogID": srcFile.Id,
|
||||
"catalogName": utils.Base(dst),
|
||||
"commonAccountInfo": base.Json{
|
||||
"account": "18627147660",
|
||||
"accountType": 1,
|
||||
},
|
||||
}
|
||||
pathname = "/orchestration/personalCloud/catalog/v1.0/updateCatalogInfo"
|
||||
} else {
|
||||
data = base.Json{
|
||||
"contentID": srcFile.Id,
|
||||
"contentName": utils.Base(dst),
|
||||
"commonAccountInfo": base.Json{
|
||||
"account": "18627147660",
|
||||
"accountType": 1,
|
||||
},
|
||||
}
|
||||
pathname = "/orchestration/personalCloud/catalog/v1.0/updateContentInfo"
|
||||
}
|
||||
_, err = driver.Post(pathname, data, nil, account)
|
||||
return err
|
||||
}
|
||||
|
||||
func (driver Cloud139) Copy(src string, dst string, account *model.Account) error {
|
||||
if isFamily(account) {
|
||||
return base.ErrNotSupport
|
||||
}
|
||||
srcFile, err := driver.File(src, account)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
dstParentFile, err := driver.File(utils.Dir(dst), account)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
var contentInfoList []string
|
||||
var catalogInfoList []string
|
||||
if srcFile.IsDir() {
|
||||
catalogInfoList = append(catalogInfoList, srcFile.Id)
|
||||
} else {
|
||||
contentInfoList = append(contentInfoList, srcFile.Id)
|
||||
}
|
||||
data := base.Json{
|
||||
"createBatchOprTaskReq": base.Json{
|
||||
"taskType": 3,
|
||||
"actionType": 309,
|
||||
"taskInfo": base.Json{
|
||||
"contentInfoList": contentInfoList,
|
||||
"catalogInfoList": catalogInfoList,
|
||||
"newCatalogID": dstParentFile.Id,
|
||||
},
|
||||
"commonAccountInfo": base.Json{
|
||||
"account": "18627147660",
|
||||
"accountType": 1,
|
||||
},
|
||||
},
|
||||
}
|
||||
pathname := "/orchestration/personalCloud/batchOprTask/v1.0/createBatchOprTask"
|
||||
_, err = driver.Post(pathname, data, nil, account)
|
||||
return err
|
||||
}
|
||||
|
||||
func (driver Cloud139) Delete(path string, account *model.Account) error {
|
||||
file, err := driver.File(path, account)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
var contentInfoList []string
|
||||
var catalogInfoList []string
|
||||
if file.IsDir() {
|
||||
catalogInfoList = append(catalogInfoList, file.Id)
|
||||
} else {
|
||||
contentInfoList = append(contentInfoList, file.Id)
|
||||
}
|
||||
data := base.Json{
|
||||
"createBatchOprTaskReq": base.Json{
|
||||
"taskType": 2,
|
||||
"actionType": 201,
|
||||
"taskInfo": base.Json{
|
||||
"newCatalogID": "",
|
||||
"contentInfoList": contentInfoList,
|
||||
"catalogInfoList": contentInfoList,
|
||||
},
|
||||
"commonAccountInfo": base.Json{
|
||||
"account": "18627147660",
|
||||
"accountType": 1,
|
||||
},
|
||||
},
|
||||
}
|
||||
pathname := "/orchestration/personalCloud/batchOprTask/v1.0/createBatchOprTask"
|
||||
if isFamily(account) {
|
||||
data = base.Json{
|
||||
"catalogList": catalogInfoList,
|
||||
"contentList": contentInfoList,
|
||||
"commonAccountInfo": base.Json{
|
||||
"account": "18627147660",
|
||||
"accountType": 1,
|
||||
},
|
||||
"sourceCatalogType": 1002,
|
||||
"taskType": 2,
|
||||
}
|
||||
pathname = "/orchestration/familyCloud/batchOprTask/v1.0/createBatchOprTask"
|
||||
}
|
||||
_, err = driver.Post(pathname, data, nil, account)
|
||||
return err
|
||||
}
|
||||
|
||||
func (driver Cloud139) Upload(file *model.FileStream, account *model.Account) error {
|
||||
if file == nil {
|
||||
return base.ErrEmptyFile
|
||||
}
|
||||
parentFile, err := driver.File(file.ParentPath, account)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if !parentFile.IsDir() {
|
||||
return base.ErrNotFolder
|
||||
}
|
||||
data := base.Json{
|
||||
"manualRename": 2,
|
||||
"operation": 0,
|
||||
"fileCount": 1,
|
||||
"totalSize": file.Size,
|
||||
"uploadContentList": []base.Json{{
|
||||
"contentName": file.Name,
|
||||
"contentSize": file.Size,
|
||||
// "digest": "5a3231986ce7a6b46e408612d385bafa"
|
||||
}},
|
||||
"parentCatalogID": parentFile.Id,
|
||||
"newCatalogName": "",
|
||||
"commonAccountInfo": base.Json{
|
||||
"account": "18627147660",
|
||||
"accountType": 1,
|
||||
},
|
||||
}
|
||||
pathname := "/orchestration/personalCloud/uploadAndDownload/v1.0/pcUploadFileRequest"
|
||||
if isFamily(account) {
|
||||
data = newJson(base.Json{
|
||||
"fileCount": 1,
|
||||
"manualRename": 2,
|
||||
"operation": 0,
|
||||
"path": "",
|
||||
"seqNo": "",
|
||||
"totalSize": file.Size,
|
||||
"uploadContentList": []base.Json{{
|
||||
"contentName": file.Name,
|
||||
"contentSize": file.Size,
|
||||
// "digest": "5a3231986ce7a6b46e408612d385bafa"
|
||||
}},
|
||||
}, account)
|
||||
pathname = "/orchestration/familyCloud/content/v1.0/getFileUploadURL"
|
||||
return base.ErrNotSupport
|
||||
}
|
||||
var resp UploadResp
|
||||
_, err = driver.Post(pathname, data, &resp, account)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
var Default uint64 = 10485760
|
||||
part := int(math.Ceil(float64(file.Size) / float64(Default)))
|
||||
var start uint64 = 0
|
||||
for i := 0; i < part; i++ {
|
||||
byteSize := file.Size - start
|
||||
if byteSize > Default {
|
||||
byteSize = Default
|
||||
}
|
||||
byteData := make([]byte, byteSize)
|
||||
_, err = io.ReadFull(file, byteData)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
req, err := http.NewRequest("POST", resp.Data.UploadResult.RedirectionURL, bytes.NewBuffer(byteData))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
headers := map[string]string{
|
||||
"Accept": "*/*",
|
||||
"Content-Type": "text/plain;name=" + unicode(file.Name),
|
||||
"contentSize": strconv.FormatUint(file.Size, 10),
|
||||
"range": fmt.Sprintf("bytes=%d-%d", start, start+byteSize-1),
|
||||
"content-length": strconv.FormatUint(byteSize, 10),
|
||||
"uploadtaskID": resp.Data.UploadResult.UploadTaskID,
|
||||
"rangeType": "0",
|
||||
"Referer": "https://yun.139.com/",
|
||||
"User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/95.0.4638.69 Safari/537.36 Edg/95.0.1020.44",
|
||||
"x-SvcType": "1",
|
||||
}
|
||||
for k, v := range headers {
|
||||
req.Header.Set(k, v)
|
||||
}
|
||||
res, err := base.HttpClient.Do(req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
log.Debugf("%+v", res)
|
||||
start += byteSize
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
var _ base.Driver = (*Cloud139)(nil)
|
74
drivers/139/family.go
Normal file
74
drivers/139/family.go
Normal file
@ -0,0 +1,74 @@
|
||||
package _39
|
||||
|
||||
import (
|
||||
"github.com/Xhofe/alist/conf"
|
||||
"github.com/Xhofe/alist/drivers/base"
|
||||
"github.com/Xhofe/alist/model"
|
||||
"github.com/Xhofe/alist/utils"
|
||||
jsoniter "github.com/json-iterator/go"
|
||||
"path"
|
||||
)
|
||||
|
||||
func (driver Cloud139) familyGetFiles(catalogID string, account *model.Account) ([]model.File, error) {
|
||||
pageNum := 1
|
||||
files := make([]model.File, 0)
|
||||
for {
|
||||
data := newJson(base.Json{
|
||||
"catalogID": catalogID,
|
||||
"contentSortType": 0,
|
||||
"pageInfo": base.Json{
|
||||
"pageNum": pageNum,
|
||||
"pageSize": 100,
|
||||
},
|
||||
"sortDirection": 1,
|
||||
}, account)
|
||||
|
||||
var resp QueryContentListResp
|
||||
_, err := driver.Post("/orchestration/familyCloud/content/v1.0/queryContentList", data, &resp, account)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
for _, catalog := range resp.Data.CloudCatalogList {
|
||||
f := model.File{
|
||||
Id: catalog.CatalogID,
|
||||
Name: catalog.CatalogName,
|
||||
Size: 0,
|
||||
Type: conf.FOLDER,
|
||||
Driver: driver.Config().Name,
|
||||
UpdatedAt: getTime(catalog.LastUpdateTime),
|
||||
}
|
||||
files = append(files, f)
|
||||
}
|
||||
for _, content := range resp.Data.CloudContentList {
|
||||
f := model.File{
|
||||
Id: content.ContentID,
|
||||
Name: content.ContentName,
|
||||
Size: int64(content.ContentSize),
|
||||
Type: utils.GetFileType(path.Ext(content.ContentName)),
|
||||
Driver: driver.Config().Name,
|
||||
UpdatedAt: getTime(content.LastUpdateTime),
|
||||
Thumbnail: content.ThumbnailURL,
|
||||
//Thumbnail: content.BigthumbnailURL,
|
||||
}
|
||||
files = append(files, f)
|
||||
}
|
||||
if 100*pageNum > resp.Data.TotalCount {
|
||||
break
|
||||
}
|
||||
pageNum++
|
||||
}
|
||||
return files, nil
|
||||
}
|
||||
|
||||
func (driver Cloud139) familyLink(contentId string, account *model.Account) (string, error) {
|
||||
data := newJson(base.Json{
|
||||
"contentID": contentId,
|
||||
//"path":"",
|
||||
}, account)
|
||||
res, err := driver.Post("/orchestration/familyCloud/content/v1.0/getFileDownLoadURL",
|
||||
data, nil, account)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
return jsoniter.Get(res, "data", "downloadURL").ToString(), nil
|
||||
}
|
187
drivers/139/types.go
Normal file
187
drivers/139/types.go
Normal file
@ -0,0 +1,187 @@
|
||||
package _39
|
||||
|
||||
type BaseResp struct {
|
||||
Success bool `json:"success"`
|
||||
Code string `json:"code"`
|
||||
Message string `json:"message"`
|
||||
}
|
||||
|
||||
type Catalog struct {
|
||||
CatalogID string `json:"catalogID"`
|
||||
CatalogName string `json:"catalogName"`
|
||||
//CatalogType int `json:"catalogType"`
|
||||
//CreateTime string `json:"createTime"`
|
||||
UpdateTime string `json:"updateTime"`
|
||||
//IsShared bool `json:"isShared"`
|
||||
//CatalogLevel int `json:"catalogLevel"`
|
||||
//ShareDoneeCount int `json:"shareDoneeCount"`
|
||||
//OpenType int `json:"openType"`
|
||||
//ParentCatalogID string `json:"parentCatalogId"`
|
||||
//DirEtag int `json:"dirEtag"`
|
||||
//Tombstoned int `json:"tombstoned"`
|
||||
//ProxyID interface{} `json:"proxyID"`
|
||||
//Moved int `json:"moved"`
|
||||
//IsFixedDir int `json:"isFixedDir"`
|
||||
//IsSynced interface{} `json:"isSynced"`
|
||||
//Owner string `json:"owner"`
|
||||
//Modifier interface{} `json:"modifier"`
|
||||
//Path string `json:"path"`
|
||||
//ShareType int `json:"shareType"`
|
||||
//SoftLink interface{} `json:"softLink"`
|
||||
//ExtProp1 interface{} `json:"extProp1"`
|
||||
//ExtProp2 interface{} `json:"extProp2"`
|
||||
//ExtProp3 interface{} `json:"extProp3"`
|
||||
//ExtProp4 interface{} `json:"extProp4"`
|
||||
//ExtProp5 interface{} `json:"extProp5"`
|
||||
//ETagOprType int `json:"ETagOprType"`
|
||||
}
|
||||
|
||||
type Content struct {
|
||||
ContentID string `json:"contentID"`
|
||||
ContentName string `json:"contentName"`
|
||||
//ContentSuffix string `json:"contentSuffix"`
|
||||
ContentSize int `json:"contentSize"`
|
||||
//ContentDesc string `json:"contentDesc"`
|
||||
//ContentType int `json:"contentType"`
|
||||
//ContentOrigin int `json:"contentOrigin"`
|
||||
UpdateTime string `json:"updateTime"`
|
||||
//CommentCount int `json:"commentCount"`
|
||||
ThumbnailURL string `json:"thumbnailURL"`
|
||||
//BigthumbnailURL string `json:"bigthumbnailURL"`
|
||||
//PresentURL string `json:"presentURL"`
|
||||
//PresentLURL string `json:"presentLURL"`
|
||||
//PresentHURL string `json:"presentHURL"`
|
||||
//ContentTAGList interface{} `json:"contentTAGList"`
|
||||
//ShareDoneeCount int `json:"shareDoneeCount"`
|
||||
//Safestate int `json:"safestate"`
|
||||
//Transferstate int `json:"transferstate"`
|
||||
//IsFocusContent int `json:"isFocusContent"`
|
||||
//UpdateShareTime interface{} `json:"updateShareTime"`
|
||||
//UploadTime string `json:"uploadTime"`
|
||||
//OpenType int `json:"openType"`
|
||||
//AuditResult int `json:"auditResult"`
|
||||
//ParentCatalogID string `json:"parentCatalogId"`
|
||||
//Channel string `json:"channel"`
|
||||
//GeoLocFlag string `json:"geoLocFlag"`
|
||||
//Digest string `json:"digest"`
|
||||
//Version string `json:"version"`
|
||||
//FileEtag string `json:"fileEtag"`
|
||||
//FileVersion string `json:"fileVersion"`
|
||||
//Tombstoned int `json:"tombstoned"`
|
||||
//ProxyID string `json:"proxyID"`
|
||||
//Moved int `json:"moved"`
|
||||
//MidthumbnailURL string `json:"midthumbnailURL"`
|
||||
//Owner string `json:"owner"`
|
||||
//Modifier string `json:"modifier"`
|
||||
//ShareType int `json:"shareType"`
|
||||
//ExtInfo struct {
|
||||
// Uploader string `json:"uploader"`
|
||||
// Address string `json:"address"`
|
||||
//} `json:"extInfo"`
|
||||
//Exif struct {
|
||||
// CreateTime string `json:"createTime"`
|
||||
// Longitude interface{} `json:"longitude"`
|
||||
// Latitude interface{} `json:"latitude"`
|
||||
// LocalSaveTime interface{} `json:"localSaveTime"`
|
||||
//} `json:"exif"`
|
||||
//CollectionFlag interface{} `json:"collectionFlag"`
|
||||
//TreeInfo interface{} `json:"treeInfo"`
|
||||
//IsShared bool `json:"isShared"`
|
||||
//ETagOprType int `json:"ETagOprType"`
|
||||
}
|
||||
|
||||
type GetDiskResp struct {
|
||||
BaseResp
|
||||
Data struct {
|
||||
Result struct {
|
||||
ResultCode string `json:"resultCode"`
|
||||
ResultDesc interface{} `json:"resultDesc"`
|
||||
} `json:"result"`
|
||||
GetDiskResult struct {
|
||||
ParentCatalogID string `json:"parentCatalogID"`
|
||||
NodeCount int `json:"nodeCount"`
|
||||
CatalogList []Catalog `json:"catalogList"`
|
||||
ContentList []Content `json:"contentList"`
|
||||
IsCompleted int `json:"isCompleted"`
|
||||
} `json:"getDiskResult"`
|
||||
} `json:"data"`
|
||||
}
|
||||
|
||||
type UploadResp struct {
|
||||
BaseResp
|
||||
Data struct {
|
||||
Result struct {
|
||||
ResultCode string `json:"resultCode"`
|
||||
ResultDesc interface{} `json:"resultDesc"`
|
||||
} `json:"result"`
|
||||
UploadResult struct {
|
||||
UploadTaskID string `json:"uploadTaskID"`
|
||||
RedirectionURL string `json:"redirectionUrl"`
|
||||
NewContentIDList []struct {
|
||||
ContentID string `json:"contentID"`
|
||||
ContentName string `json:"contentName"`
|
||||
IsNeedUpload string `json:"isNeedUpload"`
|
||||
FileEtag int64 `json:"fileEtag"`
|
||||
FileVersion int64 `json:"fileVersion"`
|
||||
OverridenFlag int `json:"overridenFlag"`
|
||||
} `json:"newContentIDList"`
|
||||
CatalogIDList interface{} `json:"catalogIDList"`
|
||||
IsSlice interface{} `json:"isSlice"`
|
||||
} `json:"uploadResult"`
|
||||
} `json:"data"`
|
||||
}
|
||||
|
||||
type CloudContent struct {
|
||||
ContentID string `json:"contentID"`
|
||||
Modifier string `json:"modifier"`
|
||||
Nickname string `json:"nickname"`
|
||||
CloudNickName string `json:"cloudNickName"`
|
||||
ContentName string `json:"contentName"`
|
||||
ContentType int `json:"contentType"`
|
||||
ContentSuffix string `json:"contentSuffix"`
|
||||
ContentSize int `json:"contentSize"`
|
||||
ContentDesc string `json:"contentDesc"`
|
||||
CreateTime string `json:"createTime"`
|
||||
Shottime interface{} `json:"shottime"`
|
||||
LastUpdateTime string `json:"lastUpdateTime"`
|
||||
ThumbnailURL string `json:"thumbnailURL"`
|
||||
MidthumbnailURL string `json:"midthumbnailURL"`
|
||||
BigthumbnailURL string `json:"bigthumbnailURL"`
|
||||
PresentURL string `json:"presentURL"`
|
||||
PresentLURL string `json:"presentLURL"`
|
||||
PresentHURL string `json:"presentHURL"`
|
||||
ParentCatalogID string `json:"parentCatalogID"`
|
||||
Uploader string `json:"uploader"`
|
||||
UploaderNickName string `json:"uploaderNickName"`
|
||||
TreeInfo interface{} `json:"treeInfo"`
|
||||
UpdateTime interface{} `json:"updateTime"`
|
||||
ExtInfo struct {
|
||||
Uploader string `json:"uploader"`
|
||||
} `json:"extInfo"`
|
||||
EtagOprType interface{} `json:"etagOprType"`
|
||||
}
|
||||
|
||||
type CloudCatalog struct {
|
||||
CatalogID string `json:"catalogID"`
|
||||
CatalogName string `json:"catalogName"`
|
||||
CloudID string `json:"cloudID"`
|
||||
CreateTime string `json:"createTime"`
|
||||
LastUpdateTime string `json:"lastUpdateTime"`
|
||||
Creator string `json:"creator"`
|
||||
CreatorNickname string `json:"creatorNickname"`
|
||||
}
|
||||
|
||||
type QueryContentListResp struct {
|
||||
BaseResp
|
||||
Data struct {
|
||||
Result struct {
|
||||
ResultCode string `json:"resultCode"`
|
||||
ResultDesc string `json:"resultDesc"`
|
||||
} `json:"result"`
|
||||
Path string `json:"path"`
|
||||
CloudContentList []CloudContent `json:"cloudContentList"`
|
||||
CloudCatalogList []CloudCatalog `json:"cloudCatalogList"`
|
||||
TotalCount int `json:"totalCount"`
|
||||
RecallContent interface{} `json:"recallContent"`
|
||||
} `json:"data"`
|
||||
}
|
81
drivers/139/util.go
Normal file
81
drivers/139/util.go
Normal file
@ -0,0 +1,81 @@
|
||||
package _39
|
||||
|
||||
import (
|
||||
"encoding/base64"
|
||||
"github.com/Xhofe/alist/drivers/base"
|
||||
"github.com/Xhofe/alist/model"
|
||||
"github.com/Xhofe/alist/utils"
|
||||
"math/rand"
|
||||
"net/url"
|
||||
"sort"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
func randomStr(n int) string {
|
||||
builder := strings.Builder{}
|
||||
t := "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"
|
||||
for i := 0; i < n; i++ {
|
||||
r := rand.Intn(len(t))
|
||||
builder.WriteString(t[r : r+1])
|
||||
}
|
||||
return builder.String()
|
||||
}
|
||||
|
||||
func encodeURIComponent(str string) string {
|
||||
r := url.QueryEscape(str)
|
||||
r = strings.Replace(r, "+", "%20", -1)
|
||||
return r
|
||||
}
|
||||
|
||||
func calSign(body, ts, randStr string) string {
|
||||
body = strings.ReplaceAll(body, "\n", "")
|
||||
body = strings.ReplaceAll(body, " ", "")
|
||||
body = encodeURIComponent(body)
|
||||
strs := strings.Split(body, "")
|
||||
sort.Strings(strs)
|
||||
body = strings.Join(strs, "")
|
||||
body = base64.StdEncoding.EncodeToString([]byte(body))
|
||||
res := utils.GetMD5Encode(body) + utils.GetMD5Encode(ts+":"+randStr)
|
||||
res = strings.ToUpper(utils.GetMD5Encode(res))
|
||||
return res
|
||||
}
|
||||
|
||||
func getTime(t string) *time.Time {
|
||||
stamp, _ := time.ParseInLocation("20060102150405", t, time.Local)
|
||||
return &stamp
|
||||
}
|
||||
|
||||
func isFamily(account *model.Account) bool {
|
||||
return account.InternalType == "Family"
|
||||
}
|
||||
|
||||
func unicode(str string) string {
|
||||
textQuoted := strconv.QuoteToASCII(str)
|
||||
textUnquoted := textQuoted[1 : len(textQuoted)-1]
|
||||
return textUnquoted
|
||||
}
|
||||
|
||||
func MergeMap(mObj ...map[string]interface{}) map[string]interface{} {
|
||||
newObj := map[string]interface{}{}
|
||||
for _, m := range mObj {
|
||||
for k, v := range m {
|
||||
newObj[k] = v
|
||||
}
|
||||
}
|
||||
return newObj
|
||||
}
|
||||
|
||||
func newJson(data map[string]interface{}, account *model.Account) map[string]interface{} {
|
||||
common := map[string]interface{}{
|
||||
"catalogType": 3,
|
||||
"cloudID": account.SiteId,
|
||||
"cloudType": 1,
|
||||
"commonAccountInfo": base.Json{
|
||||
"account": account.Username,
|
||||
"accountType": 1,
|
||||
},
|
||||
}
|
||||
return MergeMap(data, common)
|
||||
}
|
@ -1,6 +1,7 @@
|
||||
package _89
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"crypto/aes"
|
||||
"crypto/hmac"
|
||||
"crypto/md5"
|
||||
@ -10,7 +11,6 @@ import (
|
||||
"crypto/x509"
|
||||
"encoding/base64"
|
||||
"encoding/hex"
|
||||
"encoding/json"
|
||||
"encoding/pem"
|
||||
"errors"
|
||||
"fmt"
|
||||
@ -19,9 +19,13 @@ import (
|
||||
"github.com/Xhofe/alist/model"
|
||||
"github.com/Xhofe/alist/utils"
|
||||
"github.com/go-resty/resty/v2"
|
||||
"github.com/google/uuid"
|
||||
jsoniter "github.com/json-iterator/go"
|
||||
log "github.com/sirupsen/logrus"
|
||||
"io"
|
||||
"math"
|
||||
mathRand "math/rand"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
@ -108,6 +112,10 @@ func (driver Cloud189) Login(account *model.Account) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
// 已经登陆
|
||||
if res.RawResponse.Request.URL.String() == "https://cloud.189.cn/web/main" {
|
||||
return nil
|
||||
}
|
||||
b = res.String()
|
||||
ltTextArr := ltText.FindStringSubmatch(b)
|
||||
if len(ltTextArr) > 0 {
|
||||
@ -158,7 +166,7 @@ func (driver Cloud189) Login(account *model.Account) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = json.Unmarshal(res.Body(), &loginResp)
|
||||
err = utils.Json.Unmarshal(res.Body(), &loginResp)
|
||||
if err != nil {
|
||||
log.Error(err.Error())
|
||||
return err
|
||||
@ -208,39 +216,32 @@ type Cloud189Files struct {
|
||||
} `json:"fileListAO"`
|
||||
}
|
||||
|
||||
func (driver Cloud189) isFamily(account *model.Account) bool {
|
||||
return account.InternalType == "Family"
|
||||
}
|
||||
|
||||
func (driver Cloud189) GetFiles(fileId string, account *model.Account) ([]Cloud189File, error) {
|
||||
client, ok := client189Map[account.Name]
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("can't find [%s] client", account.Name)
|
||||
}
|
||||
res := make([]Cloud189File, 0)
|
||||
pageNum := 1
|
||||
|
||||
for {
|
||||
var e Cloud189Error
|
||||
var resp Cloud189Files
|
||||
_, err := client.R().SetResult(&resp).SetError(&e).
|
||||
SetHeader("Accept", "application/json;charset=UTF-8").
|
||||
SetQueryParams(map[string]string{
|
||||
"noCache": random(),
|
||||
"pageSize": "60",
|
||||
"pageNum": strconv.Itoa(pageNum),
|
||||
"mediaType": "0",
|
||||
"folderId": fileId,
|
||||
"iconOption": "5",
|
||||
"orderBy": account.OrderBy,
|
||||
"descending": account.OrderDirection,
|
||||
}).Get("https://cloud.189.cn/api/open/file/listFiles.action")
|
||||
body, err := driver.Request("https://cloud.189.cn/api/open/file/listFiles.action", base.Get, map[string]string{
|
||||
//"noCache": random(),
|
||||
"pageSize": "60",
|
||||
"pageNum": strconv.Itoa(pageNum),
|
||||
"mediaType": "0",
|
||||
"folderId": fileId,
|
||||
"iconOption": "5",
|
||||
"orderBy": account.OrderBy,
|
||||
"descending": account.OrderDirection,
|
||||
}, nil, nil, account)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if e.ErrorCode != "" {
|
||||
if e.ErrorCode == "InvalidSessionKey" {
|
||||
err = driver.Login(account)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return driver.GetFiles(fileId, account)
|
||||
}
|
||||
err = utils.Json.Unmarshal(body, &resp)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if resp.ResCode != 0 {
|
||||
return nil, fmt.Errorf(resp.ResMessage)
|
||||
@ -262,18 +263,30 @@ func (driver Cloud189) GetFiles(fileId string, account *model.Account) ([]Cloud1
|
||||
return res, nil
|
||||
}
|
||||
|
||||
func (driver Cloud189) Request(url string, method string, form map[string]string, headers map[string]string, account *model.Account) ([]byte, error) {
|
||||
func (driver Cloud189) Request(url string, method int, query, form map[string]string, headers map[string]string, account *model.Account) ([]byte, error) {
|
||||
client, ok := client189Map[account.Name]
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("can't find [%s] client", account.Name)
|
||||
}
|
||||
//var resp base.Json
|
||||
if driver.isFamily(account) {
|
||||
url = strings.Replace(url, "/api/open", "/api/open/family", 1)
|
||||
if query != nil {
|
||||
query["familyId"] = account.SiteId
|
||||
}
|
||||
if form != nil {
|
||||
form["familyId"] = account.SiteId
|
||||
}
|
||||
}
|
||||
var e Cloud189Error
|
||||
req := client.R().SetError(&e).
|
||||
SetHeader("Accept", "application/json;charset=UTF-8").
|
||||
SetQueryParams(map[string]string{
|
||||
"noCache": random(),
|
||||
})
|
||||
if query != nil {
|
||||
req = req.SetQueryParams(query)
|
||||
}
|
||||
if form != nil {
|
||||
req = req.SetFormData(form)
|
||||
}
|
||||
@ -282,24 +295,27 @@ func (driver Cloud189) Request(url string, method string, form map[string]string
|
||||
}
|
||||
var err error
|
||||
var res *resty.Response
|
||||
if strings.ToUpper(method) == "GET" {
|
||||
switch method {
|
||||
case base.Get:
|
||||
res, err = req.Get(url)
|
||||
} else {
|
||||
case base.Post:
|
||||
res, err = req.Post(url)
|
||||
default:
|
||||
return nil, base.ErrNotSupport
|
||||
}
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
log.Debug(res.String())
|
||||
if e.ErrorCode != "" {
|
||||
if e.ErrorCode == "InvalidSessionKey" {
|
||||
err = driver.Login(account)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return driver.Request(url, method, form, nil, account)
|
||||
return driver.Request(url, method, query, form, nil, account)
|
||||
}
|
||||
}
|
||||
//log.Debug(res, jsoniter.Get(res.Body(),"res_code").ToInt())
|
||||
if jsoniter.Get(res.Body(), "res_code").ToInt() != 0 {
|
||||
err = errors.New(jsoniter.Get(res.Body(), "res_message").ToString())
|
||||
}
|
||||
@ -307,7 +323,7 @@ func (driver Cloud189) Request(url string, method string, form map[string]string
|
||||
}
|
||||
|
||||
func (driver Cloud189) GetSessionKey(account *model.Account) (string, error) {
|
||||
resp, err := driver.Request("https://cloud.189.cn/v2/getUserBriefInfo.action", "GET", nil, nil, account)
|
||||
resp, err := driver.Request("https://cloud.189.cn/v2/getUserBriefInfo.action", base.Get, nil, nil, nil, account)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
@ -315,7 +331,7 @@ func (driver Cloud189) GetSessionKey(account *model.Account) (string, error) {
|
||||
}
|
||||
|
||||
func (driver Cloud189) GetResKey(account *model.Account) (string, string, error) {
|
||||
resp, err := driver.Request("https://cloud.189.cn/api/security/generateRsaKey.action", "GET", nil, nil, account)
|
||||
resp, err := driver.Request("https://cloud.189.cn/api/security/generateRsaKey.action", base.Get, nil, nil, nil, account)
|
||||
if err != nil {
|
||||
return "", "", err
|
||||
}
|
||||
@ -331,13 +347,13 @@ func (driver Cloud189) UploadRequest(url string, form map[string]string, account
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
xRId := "e007e99a-370c-4a14-a143-1b1541972fcf"
|
||||
pkey := strings.ReplaceAll(xRId, "-", "")
|
||||
xRId := uuid.New().String()
|
||||
pkey := strings.ReplaceAll(xRId, "-", "")[:mathRand.Intn(16)+16]
|
||||
params := aesEncrypt(qs(form), pkey[:16])
|
||||
date := strconv.FormatInt(time.Now().Unix(), 10)
|
||||
signature := hmacSha1(fmt.Sprintf("SessionKey=%s&Operate=GET&RequestURI=%s&Date=%s¶ms=%s", sessionKey, url, date, params), pkey)
|
||||
encryptionText := RsaEncode([]byte(pkey), pubKey)
|
||||
res, err := base.RestyClient.R().SetHeaders(map[string]string{
|
||||
headers := map[string]string{
|
||||
"signature": signature,
|
||||
"sessionKey": sessionKey,
|
||||
"encryptionText": encryptionText,
|
||||
@ -346,7 +362,9 @@ func (driver Cloud189) UploadRequest(url string, form map[string]string, account
|
||||
"x-request-date": date,
|
||||
"origin": "https://cloud.189.cn",
|
||||
"referer": "https://cloud.189.cn/",
|
||||
}).SetQueryParam("params", params).Get("https://upload.cloud.189.cn" + url)
|
||||
}
|
||||
log.Debugf("%+v\n%s", headers, params)
|
||||
res, err := base.RestyClient.R().SetHeaders(headers).SetQueryParam("params", params).Get("https://upload.cloud.189.cn" + url)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -358,6 +376,84 @@ func (driver Cloud189) UploadRequest(url string, form map[string]string, account
|
||||
return data, nil
|
||||
}
|
||||
|
||||
// Upload Error: decrypt encryptionText failed
|
||||
func (driver Cloud189) NewUpload(file *model.FileStream, account *model.Account) error {
|
||||
const DEFAULT uint64 = 10485760
|
||||
var count = int64(math.Ceil(float64(file.GetSize()) / float64(DEFAULT)))
|
||||
var finish uint64 = 0
|
||||
parentFile, err := driver.File(file.ParentPath, account)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if !parentFile.IsDir() {
|
||||
return base.ErrNotFolder
|
||||
}
|
||||
res, err := driver.UploadRequest("/person/initMultiUpload", map[string]string{
|
||||
"parentFolderId": parentFile.Id,
|
||||
"fileName": file.Name,
|
||||
"fileSize": strconv.FormatInt(int64(file.Size), 10),
|
||||
"sliceSize": strconv.FormatInt(int64(DEFAULT), 10),
|
||||
"lazyCheck": "1",
|
||||
}, account)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
uploadFileId := jsoniter.Get(res, "data.uploadFileId").ToString()
|
||||
var i int64
|
||||
var byteSize uint64
|
||||
md5s := make([]string, 0)
|
||||
md5Sum := md5.New()
|
||||
for i = 1; i <= count; i++ {
|
||||
byteSize = file.GetSize() - finish
|
||||
if DEFAULT < byteSize {
|
||||
byteSize = DEFAULT
|
||||
}
|
||||
log.Debugf("%d,%d", byteSize, finish)
|
||||
byteData := make([]byte, byteSize)
|
||||
n, err := io.ReadFull(file, byteData)
|
||||
log.Debug(err, n)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
finish += uint64(n)
|
||||
md5Bytes := getMd5(byteData)
|
||||
md5Str := hex.EncodeToString(md5Bytes)
|
||||
md5Base64 := base64.StdEncoding.EncodeToString(md5Bytes)
|
||||
md5s = append(md5s, md5Str)
|
||||
md5Sum.Write(byteData)
|
||||
res, err = driver.UploadRequest("/person/getMultiUploadUrls", map[string]string{
|
||||
"partInfo": fmt.Sprintf("%s-%s", strconv.FormatInt(i, 10), md5Base64),
|
||||
"uploadFileId": uploadFileId,
|
||||
}, account)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
uploadData := jsoniter.Get(res, "uploadUrls.partNumber_"+strconv.FormatInt(i, 10))
|
||||
headers := strings.Split(uploadData.Get("requestHeader").ToString(), "&")
|
||||
req, err := http.NewRequest("PUT", uploadData.Get("requestURL").ToString(), bytes.NewBuffer(byteData))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for _, header := range headers {
|
||||
kv := strings.Split(header, "=")
|
||||
req.Header.Set(kv[0], strings.Join(kv[1:], "="))
|
||||
}
|
||||
res, err := base.HttpClient.Do(req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
log.Debugf("%+v", res)
|
||||
}
|
||||
id := md5Sum.Sum(nil)
|
||||
res, err = driver.UploadRequest("/person/commitMultiUploadFile", map[string]string{
|
||||
"uploadFileId": uploadFileId,
|
||||
"fileMd5": hex.EncodeToString(id),
|
||||
"sliceMd5": utils.GetMD5Encode(strings.Join(md5s, "\n")),
|
||||
"lazyCheck": "1",
|
||||
}, account)
|
||||
return err
|
||||
}
|
||||
|
||||
func random() string {
|
||||
return fmt.Sprintf("0.%17v", mathRand.New(mathRand.NewSource(time.Now().UnixNano())).Int63n(100000000000000000))
|
||||
}
|
||||
|
@ -1,11 +1,7 @@
|
||||
package _89
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"crypto/md5"
|
||||
"encoding/base64"
|
||||
"encoding/hex"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"github.com/Xhofe/alist/conf"
|
||||
"github.com/Xhofe/alist/drivers/base"
|
||||
@ -14,12 +10,7 @@ import (
|
||||
"github.com/gin-gonic/gin"
|
||||
jsoniter "github.com/json-iterator/go"
|
||||
log "github.com/sirupsen/logrus"
|
||||
"io"
|
||||
"math"
|
||||
"net/http"
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type Cloud189 struct{}
|
||||
@ -52,6 +43,18 @@ func (driver Cloud189) Items() []base.Item {
|
||||
Type: base.TypeString,
|
||||
Required: true,
|
||||
},
|
||||
//{
|
||||
// Name: "internal_type",
|
||||
// Label: "189cloud type",
|
||||
// Type: base.TypeSelect,
|
||||
// Required: true,
|
||||
// Values: "Personal,Family",
|
||||
//},
|
||||
//{
|
||||
// Name: "site_id",
|
||||
// Label: "family id",
|
||||
// Type: base.TypeString,
|
||||
//},
|
||||
{
|
||||
Name: "order_by",
|
||||
Label: "order_by",
|
||||
@ -78,12 +81,15 @@ func (driver Cloud189) Save(account *model.Account, old *model.Account) error {
|
||||
_ = model.SaveAccount(account)
|
||||
return err
|
||||
}
|
||||
account.Status = "work"
|
||||
err := model.SaveAccount(account)
|
||||
sessionKey, err := driver.GetSessionKey(account)
|
||||
if err != nil {
|
||||
return err
|
||||
account.Status = err.Error()
|
||||
} else {
|
||||
account.Status = "work"
|
||||
account.DriveId = sessionKey
|
||||
}
|
||||
return nil
|
||||
_ = model.SaveAccount(account)
|
||||
return err
|
||||
}
|
||||
|
||||
func (driver Cloud189) File(path string, account *model.Account) (*model.File, error) {
|
||||
@ -145,29 +151,17 @@ func (driver Cloud189) Link(args base.Args, account *model.Account) (*base.Link,
|
||||
if file.Type == conf.FOLDER {
|
||||
return nil, base.ErrNotFile
|
||||
}
|
||||
client, ok := client189Map[account.Name]
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("can't find [%s] client", account.Name)
|
||||
}
|
||||
var e Cloud189Error
|
||||
var resp Cloud189Down
|
||||
_, err = client.R().SetResult(&resp).SetError(&e).
|
||||
SetHeader("Accept", "application/json;charset=UTF-8").
|
||||
SetQueryParams(map[string]string{
|
||||
"noCache": random(),
|
||||
"fileId": file.Id,
|
||||
}).Get("https://cloud.189.cn/api/open/file/getFileDownloadUrl.action")
|
||||
u := "https://cloud.189.cn/api/open/file/getFileDownloadUrl.action"
|
||||
body, err := driver.Request(u, base.Get, map[string]string{
|
||||
"fileId": file.Id,
|
||||
}, nil, nil, account)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if e.ErrorCode != "" {
|
||||
if e.ErrorCode == "InvalidSessionKey" {
|
||||
err = driver.Login(account)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return driver.Link(args, account)
|
||||
}
|
||||
err = utils.Json.Unmarshal(body, &resp)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if resp.ResCode != 0 {
|
||||
return nil, fmt.Errorf(resp.ResMessage)
|
||||
@ -223,67 +217,63 @@ func (driver Cloud189) MakeDir(path string, account *model.Account) error {
|
||||
"parentFolderId": parent.Id,
|
||||
"folderName": name,
|
||||
}
|
||||
_, err = driver.Request("https://cloud.189.cn/api/open/file/createFolder.action", "POST", form, nil, account)
|
||||
if err == nil {
|
||||
_ = base.DeleteCache(dir, account)
|
||||
}
|
||||
_, err = driver.Request("https://cloud.189.cn/api/open/file/createFolder.action", base.Post, nil, form, nil, account)
|
||||
return err
|
||||
}
|
||||
|
||||
func (driver Cloud189) Move(src string, dst string, account *model.Account) error {
|
||||
srcDir, _ := filepath.Split(src)
|
||||
dstDir, dstName := filepath.Split(dst)
|
||||
srcFile, err := driver.File(src, account)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
// rename
|
||||
if srcDir == dstDir {
|
||||
url := "https://cloud.189.cn/api/open/file/renameFile.action"
|
||||
idKey := "fileId"
|
||||
nameKey := "destFileName"
|
||||
if srcFile.IsDir() {
|
||||
url = "https://cloud.189.cn/api/open/file/renameFolder.action"
|
||||
idKey = "folderId"
|
||||
nameKey = "destFolderName"
|
||||
}
|
||||
form := map[string]string{
|
||||
idKey: srcFile.Id,
|
||||
nameKey: dstName,
|
||||
}
|
||||
_, err = driver.Request(url, "POST", form, nil, account)
|
||||
} else {
|
||||
// move
|
||||
dstDirFile, err := driver.File(dstDir, account)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
isFolder := 0
|
||||
if srcFile.IsDir() {
|
||||
isFolder = 1
|
||||
}
|
||||
taskInfos := []base.Json{
|
||||
{
|
||||
"fileId": srcFile.Id,
|
||||
"fileName": dstName,
|
||||
"isFolder": isFolder,
|
||||
},
|
||||
}
|
||||
taskInfosBytes, err := json.Marshal(taskInfos)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
form := map[string]string{
|
||||
"type": "MOVE",
|
||||
"targetFolderId": dstDirFile.Id,
|
||||
"taskInfos": string(taskInfosBytes),
|
||||
}
|
||||
_, err = driver.Request("https://cloud.189.cn/api/open/batch/createBatchTask.action", "POST", form, nil, account)
|
||||
dstDirFile, err := driver.File(dstDir, account)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if err == nil {
|
||||
_ = base.DeleteCache(srcDir, account)
|
||||
_ = base.DeleteCache(dstDir, account)
|
||||
isFolder := 0
|
||||
if srcFile.IsDir() {
|
||||
isFolder = 1
|
||||
}
|
||||
taskInfos := []base.Json{
|
||||
{
|
||||
"fileId": srcFile.Id,
|
||||
"fileName": dstName,
|
||||
"isFolder": isFolder,
|
||||
},
|
||||
}
|
||||
taskInfosBytes, err := utils.Json.Marshal(taskInfos)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
form := map[string]string{
|
||||
"type": "MOVE",
|
||||
"targetFolderId": dstDirFile.Id,
|
||||
"taskInfos": string(taskInfosBytes),
|
||||
}
|
||||
_, err = driver.Request("https://cloud.189.cn/api/open/batch/createBatchTask.action", base.Post, nil, form, nil, account)
|
||||
return err
|
||||
}
|
||||
|
||||
func (driver Cloud189) Rename(src string, dst string, account *model.Account) error {
|
||||
_, dstName := filepath.Split(dst)
|
||||
srcFile, err := driver.File(src, account)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
url := "https://cloud.189.cn/api/open/file/renameFile.action"
|
||||
idKey := "fileId"
|
||||
nameKey := "destFileName"
|
||||
if srcFile.IsDir() {
|
||||
url = "https://cloud.189.cn/api/open/file/renameFolder.action"
|
||||
idKey = "folderId"
|
||||
nameKey = "destFolderName"
|
||||
}
|
||||
form := map[string]string{
|
||||
idKey: srcFile.Id,
|
||||
nameKey: dstName,
|
||||
}
|
||||
_, err = driver.Request(url, base.Post, nil, form, nil, account)
|
||||
return err
|
||||
}
|
||||
|
||||
@ -308,7 +298,7 @@ func (driver Cloud189) Copy(src string, dst string, account *model.Account) erro
|
||||
"isFolder": isFolder,
|
||||
},
|
||||
}
|
||||
taskInfosBytes, err := json.Marshal(taskInfos)
|
||||
taskInfosBytes, err := utils.Json.Marshal(taskInfos)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -317,10 +307,7 @@ func (driver Cloud189) Copy(src string, dst string, account *model.Account) erro
|
||||
"targetFolderId": dstDirFile.Id,
|
||||
"taskInfos": string(taskInfosBytes),
|
||||
}
|
||||
_, err = driver.Request("https://cloud.189.cn/api/open/batch/createBatchTask.action", "POST", form, nil, account)
|
||||
if err == nil {
|
||||
_ = base.DeleteCache(dstDir, account)
|
||||
}
|
||||
_, err = driver.Request("https://cloud.189.cn/api/open/batch/createBatchTask.action", base.Post, nil, form, nil, account)
|
||||
return err
|
||||
}
|
||||
|
||||
@ -341,7 +328,7 @@ func (driver Cloud189) Delete(path string, account *model.Account) error {
|
||||
"isFolder": isFolder,
|
||||
},
|
||||
}
|
||||
taskInfosBytes, err := json.Marshal(taskInfos)
|
||||
taskInfosBytes, err := utils.Json.Marshal(taskInfos)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -350,93 +337,38 @@ func (driver Cloud189) Delete(path string, account *model.Account) error {
|
||||
"targetFolderId": "",
|
||||
"taskInfos": string(taskInfosBytes),
|
||||
}
|
||||
_, err = driver.Request("https://cloud.189.cn/api/open/batch/createBatchTask.action", "POST", form, nil, account)
|
||||
if err == nil {
|
||||
_ = base.DeleteCache(utils.Dir(path), account)
|
||||
}
|
||||
_, err = driver.Request("https://cloud.189.cn/api/open/batch/createBatchTask.action", base.Post, nil, form, nil, account)
|
||||
return err
|
||||
}
|
||||
|
||||
// Upload Error: decrypt encryptionText failed
|
||||
func (driver Cloud189) Upload(file *model.FileStream, account *model.Account) error {
|
||||
return base.ErrNotImplement
|
||||
const DEFAULT uint64 = 10485760
|
||||
var count = int64(math.Ceil(float64(file.GetSize()) / float64(DEFAULT)))
|
||||
var finish uint64 = 0
|
||||
//return base.ErrNotImplement
|
||||
if file == nil {
|
||||
return base.ErrEmptyFile
|
||||
}
|
||||
client, ok := client189Map[account.Name]
|
||||
if !ok {
|
||||
return fmt.Errorf("can't find [%s] client", account.Name)
|
||||
}
|
||||
parentFile, err := driver.File(file.ParentPath, account)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if !parentFile.IsDir() {
|
||||
return base.ErrNotFolder
|
||||
}
|
||||
res, err := driver.UploadRequest("/person/initMultiUpload", map[string]string{
|
||||
"parentFolderId": parentFile.Id,
|
||||
"fileName": file.Name,
|
||||
"fileSize": strconv.FormatInt(int64(file.Size), 10),
|
||||
"sliceSize": strconv.FormatInt(int64(DEFAULT), 10),
|
||||
"lazyCheck": "1",
|
||||
}, account)
|
||||
// api refer to PanIndex
|
||||
res, err := client.R().SetMultipartFormData(map[string]string{
|
||||
"parentId": parentFile.Id,
|
||||
"sessionKey": account.DriveId,
|
||||
"opertype": "1",
|
||||
"fname": file.GetFileName(),
|
||||
}).SetMultipartField("Filedata", file.GetFileName(), file.GetMIMEType(), file).Post("https://hb02.upload.cloud.189.cn/v1/DCIWebUploadAction")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
uploadFileId := jsoniter.Get(res, "data.uploadFileId").ToString()
|
||||
var i int64
|
||||
var byteSize uint64
|
||||
md5s := make([]string, 0)
|
||||
md5Sum := md5.New()
|
||||
for i = 1; i <= count; i++ {
|
||||
byteSize = file.GetSize() - finish
|
||||
if DEFAULT < byteSize {
|
||||
byteSize = DEFAULT
|
||||
}
|
||||
log.Debugf("%d,%d", byteSize, finish)
|
||||
byteData := make([]byte, byteSize)
|
||||
n, err := io.ReadFull(file, byteData)
|
||||
log.Debug(err, n)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
finish += uint64(n)
|
||||
md5Bytes := getMd5(byteData)
|
||||
md5Str := hex.EncodeToString(md5Bytes)
|
||||
md5Base64 := base64.StdEncoding.EncodeToString(md5Bytes)
|
||||
md5s = append(md5s, md5Str)
|
||||
md5Sum.Write(byteData)
|
||||
res, err = driver.UploadRequest("/person/getMultiUploadUrls", map[string]string{
|
||||
"partInfo": fmt.Sprintf("%s-%s", strconv.FormatInt(i, 10), md5Base64),
|
||||
"uploadFileId": uploadFileId,
|
||||
}, account)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
uploadData := jsoniter.Get(res, "uploadUrls.partNumber_"+strconv.FormatInt(i, 10))
|
||||
headers := strings.Split(uploadData.Get("requestHeader").ToString(), "&")
|
||||
req, err := http.NewRequest("PUT", uploadData.Get("requestURL").ToString(), bytes.NewBuffer(byteData))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for _, header := range headers {
|
||||
kv := strings.Split(header, "=")
|
||||
req.Header.Set(kv[0], strings.Join(kv[1:], "="))
|
||||
}
|
||||
res, err := base.HttpClient.Do(req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
log.Debugf("%+v", res)
|
||||
if jsoniter.Get(res.Body(), "MD5").ToString() != "" {
|
||||
return nil
|
||||
}
|
||||
id := md5Sum.Sum(nil)
|
||||
res, err = driver.UploadRequest("/person/commitMultiUploadFile", map[string]string{
|
||||
"uploadFileId": uploadFileId,
|
||||
"fileMd5": hex.EncodeToString(id),
|
||||
"sliceMd5": utils.GetMD5Encode(strings.Join(md5s, "\n")),
|
||||
"lazyCheck": "1",
|
||||
}, account)
|
||||
if err == nil {
|
||||
_ = base.DeleteCache(file.ParentPath, account)
|
||||
}
|
||||
return err
|
||||
log.Debugf(res.String())
|
||||
return errors.New(res.String())
|
||||
}
|
||||
|
||||
var _ base.Driver = (*Cloud189)(nil)
|
||||
|
@ -158,7 +158,7 @@ func (driver AliDrive) RefreshToken(account *model.Account) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (driver AliDrive) Rename(fileId, name string, account *model.Account) error {
|
||||
func (driver AliDrive) rename(fileId, name string, account *model.Account) error {
|
||||
var resp base.Json
|
||||
var e AliRespError
|
||||
_, err := aliClient.R().SetResult(&resp).SetError(&e).
|
||||
@ -179,7 +179,7 @@ func (driver AliDrive) Rename(fileId, name string, account *model.Account) error
|
||||
return err
|
||||
} else {
|
||||
_ = model.SaveAccount(account)
|
||||
return driver.Rename(fileId, name, account)
|
||||
return driver.rename(fileId, name, account)
|
||||
}
|
||||
}
|
||||
return fmt.Errorf("%s", e.Message)
|
||||
@ -190,7 +190,7 @@ func (driver AliDrive) Rename(fileId, name string, account *model.Account) error
|
||||
return fmt.Errorf("%+v", resp)
|
||||
}
|
||||
|
||||
func (driver AliDrive) Batch(srcId,dstId string, account *model.Account) error {
|
||||
func (driver AliDrive) batch(srcId, dstId string, account *model.Account) error {
|
||||
var e AliRespError
|
||||
res, err := aliClient.R().SetError(&e).
|
||||
SetHeader("authorization", "Bearer\t"+account.AccessToken).
|
||||
@ -200,13 +200,13 @@ func (driver AliDrive) Batch(srcId,dstId string, account *model.Account) error {
|
||||
"headers": base.Json{
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
"method":"POST",
|
||||
"id":srcId,
|
||||
"body":base.Json{
|
||||
"drive_id": account.DriveId,
|
||||
"file_id":srcId,
|
||||
"to_drive_id":account.DriveId,
|
||||
"to_parent_file_id":dstId,
|
||||
"method": "POST",
|
||||
"id": srcId,
|
||||
"body": base.Json{
|
||||
"drive_id": account.DriveId,
|
||||
"file_id": srcId,
|
||||
"to_drive_id": account.DriveId,
|
||||
"to_parent_file_id": dstId,
|
||||
},
|
||||
},
|
||||
},
|
||||
@ -222,7 +222,7 @@ func (driver AliDrive) Batch(srcId,dstId string, account *model.Account) error {
|
||||
return err
|
||||
} else {
|
||||
_ = model.SaveAccount(account)
|
||||
return driver.Batch(srcId, dstId, account)
|
||||
return driver.batch(srcId, dstId, account)
|
||||
}
|
||||
}
|
||||
return fmt.Errorf("%s", e.Message)
|
||||
|
@ -286,34 +286,32 @@ func (driver AliDrive) MakeDir(path string, account *model.Account) error {
|
||||
return fmt.Errorf("%s", e.Message)
|
||||
}
|
||||
if resp["file_name"] == name {
|
||||
_ = base.DeleteCache(dir, account)
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("%+v", resp)
|
||||
}
|
||||
|
||||
func (driver AliDrive) Move(src string, dst string, account *model.Account) error {
|
||||
srcDir, _ := filepath.Split(src)
|
||||
dstDir, dstName := filepath.Split(dst)
|
||||
dstDir, _ := filepath.Split(dst)
|
||||
srcFile, err := driver.File(src, account)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
// rename
|
||||
if srcDir == dstDir {
|
||||
err = driver.Rename(srcFile.Id, dstName, account)
|
||||
} else {
|
||||
// move
|
||||
dstDirFile, err := driver.File(dstDir, account)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = driver.Batch(srcFile.Id, dstDirFile.Id, account)
|
||||
}
|
||||
dstDirFile, err := driver.File(dstDir, account)
|
||||
if err != nil {
|
||||
_ = base.DeleteCache(srcDir, account)
|
||||
_ = base.DeleteCache(dstDir, account)
|
||||
return err
|
||||
}
|
||||
err = driver.batch(srcFile.Id, dstDirFile.Id, account)
|
||||
return err
|
||||
}
|
||||
|
||||
func (driver AliDrive) Rename(src string, dst string, account *model.Account) error {
|
||||
_, dstName := filepath.Split(dst)
|
||||
srcFile, err := driver.File(src, account)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = driver.rename(srcFile.Id, dstName, account)
|
||||
return err
|
||||
}
|
||||
|
||||
@ -349,7 +347,6 @@ func (driver AliDrive) Delete(path string, account *model.Account) error {
|
||||
return fmt.Errorf("%s", e.Message)
|
||||
}
|
||||
if res.StatusCode() == 204 {
|
||||
_ = base.DeleteCache(utils.Dir(path), account)
|
||||
return nil
|
||||
}
|
||||
return errors.New(res.String())
|
||||
@ -471,7 +468,6 @@ func (driver AliDrive) Upload(file *model.FileStream, account *model.Account) er
|
||||
return fmt.Errorf("%s", e.Message)
|
||||
}
|
||||
if resp2["file_id"] == resp.FileId {
|
||||
_ = base.DeleteCache(file.ParentPath, account)
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("%+v", resp2)
|
||||
|
@ -13,7 +13,11 @@ type BaseResp struct {
|
||||
|
||||
type PathResp struct {
|
||||
BaseResp
|
||||
Data []model.File `json:"data"`
|
||||
Data struct {
|
||||
Type string `json:"type"`
|
||||
//Meta Meta `json:"meta"`
|
||||
Files []model.File `json:"files"`
|
||||
} `json:"data"`
|
||||
}
|
||||
|
||||
type PreviewResp struct {
|
||||
@ -25,7 +29,7 @@ func (driver *Alist) Login(account *model.Account) error {
|
||||
var resp BaseResp
|
||||
_, err := base.RestyClient.R().SetResult(&resp).
|
||||
SetHeader("Authorization", account.AccessToken).
|
||||
Get(account.SiteUrl+"/api/admin/login")
|
||||
Get(account.SiteUrl + "/api/admin/login")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -136,13 +136,13 @@ func (driver Alist) Path(path string, account *model.Account) (*model.File, []mo
|
||||
if resp.Code != 200 {
|
||||
return nil, nil, errors.New(resp.Message)
|
||||
}
|
||||
if resp.Message == "file" {
|
||||
return &resp.Data[0], nil, nil
|
||||
if resp.Data.Type == "file" {
|
||||
return &resp.Data.Files[0], nil, nil
|
||||
}
|
||||
if len(resp.Data) > 0 {
|
||||
_ = base.SetCache(path, resp.Data, account)
|
||||
if len(resp.Data.Files) > 0 {
|
||||
_ = base.SetCache(path, resp.Data.Files, account)
|
||||
}
|
||||
return nil, resp.Data, nil
|
||||
return nil, resp.Data.Files, nil
|
||||
}
|
||||
|
||||
func (driver Alist) Proxy(c *gin.Context, account *model.Account) {}
|
||||
@ -171,6 +171,10 @@ func (driver Alist) Move(src string, dst string, account *model.Account) error {
|
||||
return base.ErrNotImplement
|
||||
}
|
||||
|
||||
func (driver Alist) Rename(src string, dst string, account *model.Account) error {
|
||||
return base.ErrNotImplement
|
||||
}
|
||||
|
||||
func (driver Alist) Copy(src string, dst string, account *model.Account) error {
|
||||
return base.ErrNotImplement
|
||||
}
|
||||
|
@ -2,6 +2,7 @@ package drivers
|
||||
|
||||
import (
|
||||
_ "github.com/Xhofe/alist/drivers/123"
|
||||
_ "github.com/Xhofe/alist/drivers/139"
|
||||
_ "github.com/Xhofe/alist/drivers/189"
|
||||
_ "github.com/Xhofe/alist/drivers/alidrive"
|
||||
_ "github.com/Xhofe/alist/drivers/alist"
|
||||
@ -9,11 +10,13 @@ import (
|
||||
_ "github.com/Xhofe/alist/drivers/ftp"
|
||||
_ "github.com/Xhofe/alist/drivers/google"
|
||||
_ "github.com/Xhofe/alist/drivers/lanzou"
|
||||
_ "github.com/Xhofe/alist/drivers/mediatrack"
|
||||
_ "github.com/Xhofe/alist/drivers/native"
|
||||
_ "github.com/Xhofe/alist/drivers/onedrive"
|
||||
_ "github.com/Xhofe/alist/drivers/pikpak"
|
||||
_ "github.com/Xhofe/alist/drivers/s3"
|
||||
_ "github.com/Xhofe/alist/drivers/shandian"
|
||||
_ "github.com/Xhofe/alist/drivers/teambition"
|
||||
_ "github.com/Xhofe/alist/drivers/webdav"
|
||||
log "github.com/sirupsen/logrus"
|
||||
"strings"
|
||||
@ -32,7 +35,7 @@ func GetConfig() {
|
||||
}
|
||||
}
|
||||
NoCors = strings.Trim(NoCors, ",")
|
||||
NoUpload = strings.Trim(NoUpload, ",")
|
||||
NoUpload += "root"
|
||||
}
|
||||
|
||||
func init() {
|
||||
|
@ -46,6 +46,8 @@ type Driver interface {
|
||||
MakeDir(path string, account *model.Account) error
|
||||
// Move 移动/改名
|
||||
Move(src string, dst string, account *model.Account) error
|
||||
// Rename 改名
|
||||
Rename(src string, dst string, account *model.Account) error
|
||||
// Copy 拷贝
|
||||
Copy(src string, dst string, account *model.Account) error
|
||||
// Delete 删除
|
||||
|
@ -193,16 +193,10 @@ func (driver FTP) MakeDir(path string, account *model.Account) error {
|
||||
}
|
||||
defer func() { _ = conn.Quit() }()
|
||||
err = conn.MakeDir(realPath)
|
||||
if err == nil {
|
||||
_ = base.DeleteCache(utils.Dir(path), account)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func (driver FTP) Move(src string, dst string, account *model.Account) error {
|
||||
//if utils.Dir(src) != utils.Dir(dst) {
|
||||
// return base.ErrNotSupport
|
||||
//}
|
||||
realSrc := utils.Join(account.RootFolder, src)
|
||||
realDst := utils.Join(account.RootFolder, dst)
|
||||
conn, err := driver.Login(account)
|
||||
@ -211,15 +205,13 @@ func (driver FTP) Move(src string, dst string, account *model.Account) error {
|
||||
}
|
||||
defer func() { _ = conn.Quit() }()
|
||||
err = conn.Rename(realSrc, realDst)
|
||||
if err != nil {
|
||||
_ = base.DeleteCache(utils.Dir(src), account)
|
||||
if utils.Dir(src) != utils.Dir(dst) {
|
||||
_ = base.DeleteCache(utils.Dir(dst), account)
|
||||
}
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func (driver FTP) Rename(src string, dst string, account *model.Account) error {
|
||||
return driver.Move(src, dst, account)
|
||||
}
|
||||
|
||||
func (driver FTP) Copy(src string, dst string, account *model.Account) error {
|
||||
return base.ErrNotSupport
|
||||
}
|
||||
@ -233,9 +225,6 @@ func (driver FTP) Delete(path string, account *model.Account) error {
|
||||
}
|
||||
defer func() { _ = conn.Quit() }()
|
||||
err = conn.Delete(realPath)
|
||||
if err == nil {
|
||||
_ = base.DeleteCache(utils.Dir(path), account)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
@ -250,9 +239,6 @@ func (driver FTP) Upload(file *model.FileStream, account *model.Account) error {
|
||||
}
|
||||
defer func() { _ = conn.Quit() }()
|
||||
err = conn.Stor(realPath, file)
|
||||
if err == nil {
|
||||
_ = base.DeleteCache(utils.Dir(file.ParentPath), account)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
|
@ -194,9 +194,6 @@ func (driver GoogleDrive) MakeDir(path string, account *model.Account) error {
|
||||
"mimeType": "application/vnd.google-apps.folder",
|
||||
}
|
||||
_, err = driver.Request("https://www.googleapis.com/drive/v3/files", base.Post, nil, nil, nil, &data, nil, account)
|
||||
if err == nil {
|
||||
_ = base.DeleteCache(utils.Dir(path), account)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
@ -206,29 +203,28 @@ func (driver GoogleDrive) Move(src string, dst string, account *model.Account) e
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if utils.Dir(src) == utils.Dir(dst) {
|
||||
// rename
|
||||
data := base.Json{
|
||||
"name": utils.Base(dst),
|
||||
}
|
||||
_, err = driver.Request(url, base.Patch, nil, nil, nil, &data, nil, account)
|
||||
} else {
|
||||
dstParentFile, err := driver.File(utils.Dir(dst), account)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
query := map[string]string{
|
||||
"addParents": dstParentFile.Id,
|
||||
"removeParents": "root",
|
||||
}
|
||||
_, err = driver.Request(url, base.Patch, nil, query, nil, nil, nil, account)
|
||||
dstParentFile, err := driver.File(utils.Dir(dst), account)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if err == nil {
|
||||
_ = base.DeleteCache(utils.Dir(src), account)
|
||||
if utils.Dir(src) != utils.Dir(dst) {
|
||||
_ = base.DeleteCache(utils.Dir(dst), account)
|
||||
}
|
||||
query := map[string]string{
|
||||
"addParents": dstParentFile.Id,
|
||||
"removeParents": "root",
|
||||
}
|
||||
_, err = driver.Request(url, base.Patch, nil, query, nil, nil, nil, account)
|
||||
return err
|
||||
}
|
||||
|
||||
func (driver GoogleDrive) Rename(src string, dst string, account *model.Account) error {
|
||||
srcFile, err := driver.File(src, account)
|
||||
url := "https://www.googleapis.com/drive/v3/files/" + srcFile.Id
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
data := base.Json{
|
||||
"name": utils.Base(dst),
|
||||
}
|
||||
_, err = driver.Request(url, base.Patch, nil, nil, nil, &data, nil, account)
|
||||
return err
|
||||
}
|
||||
|
||||
@ -243,9 +239,6 @@ func (driver GoogleDrive) Delete(path string, account *model.Account) error {
|
||||
return err
|
||||
}
|
||||
_, err = driver.Request(url, base.Delete, nil, nil, nil, nil, nil, account)
|
||||
if err == nil {
|
||||
_ = base.DeleteCache(utils.Dir(path), account)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
@ -286,9 +279,6 @@ func (driver GoogleDrive) Upload(file *model.FileStream, account *model.Account)
|
||||
putUrl := res.Header().Get("location")
|
||||
byteData, _ := ioutil.ReadAll(file)
|
||||
_, err = driver.Request(putUrl, base.Put, nil, nil, nil, byteData, nil, account)
|
||||
if err == nil {
|
||||
_ = base.DeleteCache(file.ParentPath, account)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
|
@ -170,6 +170,10 @@ func (driver *Lanzou) Move(src string, dst string, account *model.Account) error
|
||||
return base.ErrNotImplement
|
||||
}
|
||||
|
||||
func (driver *Lanzou) Rename(src string, dst string, account *model.Account) error {
|
||||
return base.ErrNotImplement
|
||||
}
|
||||
|
||||
func (driver *Lanzou) Copy(src string, dst string, account *model.Account) error {
|
||||
return base.ErrNotImplement
|
||||
}
|
||||
|
292
drivers/mediatrack/driver.go
Normal file
292
drivers/mediatrack/driver.go
Normal file
@ -0,0 +1,292 @@
|
||||
package mediatrack
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"crypto/md5"
|
||||
"encoding/hex"
|
||||
"fmt"
|
||||
"github.com/Xhofe/alist/conf"
|
||||
"github.com/Xhofe/alist/drivers/base"
|
||||
"github.com/Xhofe/alist/model"
|
||||
"github.com/Xhofe/alist/utils"
|
||||
"github.com/aws/aws-sdk-go/aws"
|
||||
"github.com/aws/aws-sdk-go/aws/credentials"
|
||||
"github.com/aws/aws-sdk-go/aws/session"
|
||||
"github.com/aws/aws-sdk-go/service/s3/s3manager"
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/google/uuid"
|
||||
jsoniter "github.com/json-iterator/go"
|
||||
log "github.com/sirupsen/logrus"
|
||||
"io"
|
||||
"path/filepath"
|
||||
)
|
||||
|
||||
type MediaTrack struct{}
|
||||
|
||||
func (driver MediaTrack) Config() base.DriverConfig {
|
||||
return base.DriverConfig{
|
||||
Name: "MediaTrack",
|
||||
}
|
||||
}
|
||||
|
||||
func (driver MediaTrack) Items() []base.Item {
|
||||
return []base.Item{
|
||||
{
|
||||
Name: "access_token",
|
||||
Label: "Token",
|
||||
Type: base.TypeString,
|
||||
Description: "Unknown expiration time",
|
||||
},
|
||||
{
|
||||
Name: "root_folder",
|
||||
Label: "root folder file_id",
|
||||
Type: base.TypeString,
|
||||
},
|
||||
{
|
||||
Name: "order_by",
|
||||
Label: "order_by",
|
||||
Type: base.TypeSelect,
|
||||
Values: "updated_at,title,size",
|
||||
Required: true,
|
||||
},
|
||||
{
|
||||
Name: "order_direction",
|
||||
Label: "desc",
|
||||
Type: base.TypeSelect,
|
||||
Values: "true,false",
|
||||
Required: true,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func (driver MediaTrack) Save(account *model.Account, old *model.Account) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (driver MediaTrack) File(path string, account *model.Account) (*model.File, error) {
|
||||
path = utils.ParsePath(path)
|
||||
if path == "/" {
|
||||
return &model.File{
|
||||
Id: account.RootFolder,
|
||||
Name: account.Name,
|
||||
Size: 0,
|
||||
Type: conf.FOLDER,
|
||||
Driver: driver.Config().Name,
|
||||
UpdatedAt: account.UpdatedAt,
|
||||
}, nil
|
||||
}
|
||||
dir, name := filepath.Split(path)
|
||||
files, err := driver.Files(dir, account)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
for _, file := range files {
|
||||
if file.Name == name {
|
||||
return &file, nil
|
||||
}
|
||||
}
|
||||
return nil, base.ErrPathNotFound
|
||||
}
|
||||
|
||||
func (driver MediaTrack) Files(path string, account *model.Account) ([]model.File, error) {
|
||||
path = utils.ParsePath(path)
|
||||
var files []model.File
|
||||
cache, err := base.GetCache(path, account)
|
||||
if err == nil {
|
||||
files, _ = cache.([]model.File)
|
||||
} else {
|
||||
file, err := driver.File(path, account)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
files, err = driver.GetFiles(file.Id, account)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if len(files) > 0 {
|
||||
_ = base.SetCache(path, files, account)
|
||||
}
|
||||
}
|
||||
return files, nil
|
||||
}
|
||||
|
||||
func (driver MediaTrack) Link(args base.Args, account *model.Account) (*base.Link, error) {
|
||||
file, err := driver.File(args.Path, account)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
pre := "https://jayce.api.mediatrack.cn/v3/assets/" + file.Id
|
||||
body, err := driver.Request(pre+"/token", base.Get, nil, nil, nil, nil, nil, account)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
url := pre + "/raw"
|
||||
res, err := base.NoRedirectClient.R().SetQueryParam("token", jsoniter.Get(body, "data").ToString()).Get(url)
|
||||
return &base.Link{Url: res.Header().Get("location")}, nil
|
||||
}
|
||||
|
||||
func (driver MediaTrack) Path(path string, account *model.Account) (*model.File, []model.File, error) {
|
||||
path = utils.ParsePath(path)
|
||||
log.Debugf("MediaTrack path: %s", path)
|
||||
file, err := driver.File(path, account)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
if !file.IsDir() {
|
||||
return file, nil, nil
|
||||
}
|
||||
files, err := driver.Files(path, account)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
return nil, files, nil
|
||||
}
|
||||
|
||||
func (driver MediaTrack) Proxy(c *gin.Context, account *model.Account) {
|
||||
|
||||
}
|
||||
|
||||
func (driver MediaTrack) Preview(path string, account *model.Account) (interface{}, error) {
|
||||
return nil, base.ErrNotImplement
|
||||
}
|
||||
|
||||
func (driver MediaTrack) MakeDir(path string, account *model.Account) error {
|
||||
parentFile, err := driver.File(utils.Dir(path), account)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
url := fmt.Sprintf("https://jayce.api.mediatrack.cn/v4/assets/%s/children", parentFile.Id)
|
||||
_, err = driver.Request(url, base.Post, nil, nil, nil, base.Json{
|
||||
"type": 1,
|
||||
"title": utils.Base(path),
|
||||
}, nil, account)
|
||||
return err
|
||||
}
|
||||
|
||||
func (driver MediaTrack) Move(src string, dst string, account *model.Account) error {
|
||||
srcFile, err := driver.File(src, account)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
dstParentFile, err := driver.File(utils.Dir(dst), account)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
data := base.Json{
|
||||
"parent_id": dstParentFile.Id,
|
||||
"ids": []string{srcFile.Id},
|
||||
}
|
||||
url := "https://jayce.api.mediatrack.cn/v4/assets/batch/move"
|
||||
_, err = driver.Request(url, base.Post, nil, nil, nil, data, nil, account)
|
||||
return err
|
||||
}
|
||||
|
||||
func (driver MediaTrack) Rename(src string, dst string, account *model.Account) error {
|
||||
srcFile, err := driver.File(src, account)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
url := "https://jayce.api.mediatrack.cn/v3/assets/" + srcFile.Id
|
||||
data := base.Json{
|
||||
"title": utils.Base(dst),
|
||||
}
|
||||
_, err = driver.Request(url, base.Put, nil, nil, nil, data, nil, account)
|
||||
return err
|
||||
}
|
||||
|
||||
func (driver MediaTrack) Copy(src string, dst string, account *model.Account) error {
|
||||
srcFile, err := driver.File(src, account)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
dstParentFile, err := driver.File(utils.Dir(dst), account)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
data := base.Json{
|
||||
"parent_id": dstParentFile.Id,
|
||||
"ids": []string{srcFile.Id},
|
||||
}
|
||||
url := "https://jayce.api.mediatrack.cn/v4/assets/batch/clone"
|
||||
_, err = driver.Request(url, base.Post, nil, nil, nil, data, nil, account)
|
||||
return err
|
||||
}
|
||||
|
||||
func (driver MediaTrack) Delete(path string, account *model.Account) error {
|
||||
parentFile, err := driver.File(utils.Dir(path), account)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
file, err := driver.File(path, account)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
data := base.Json{
|
||||
"origin_id": parentFile.Id,
|
||||
"ids": []string{file.Id},
|
||||
}
|
||||
url := "https://jayce.api.mediatrack.cn/v4/assets/batch/delete"
|
||||
_, err = driver.Request(url, base.Delete, nil, nil, nil, data, nil, account)
|
||||
return err
|
||||
}
|
||||
|
||||
func (driver MediaTrack) Upload(file *model.FileStream, account *model.Account) error {
|
||||
if file == nil {
|
||||
return base.ErrEmptyFile
|
||||
}
|
||||
parentFile, err := driver.File(file.ParentPath, account)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
src := "assets/" + uuid.New().String()
|
||||
var resp UploadResp
|
||||
_, err = driver.Request("https://jayce.api.mediatrack.cn/v3/storage/tokens/asset", base.Get, nil, map[string]string{
|
||||
"src": src,
|
||||
}, nil, nil, &resp, account)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
credential := resp.Data.Credentials
|
||||
cfg := &aws.Config{
|
||||
Credentials: credentials.NewStaticCredentials(credential.TmpSecretID, credential.TmpSecretKey, credential.Token),
|
||||
Region: &resp.Data.Region,
|
||||
Endpoint: aws.String("cos.accelerate.myqcloud.com"),
|
||||
}
|
||||
s, err := session.NewSession(cfg)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
var buf bytes.Buffer
|
||||
read := io.TeeReader(file, &buf)
|
||||
uploader := s3manager.NewUploader(s)
|
||||
input := &s3manager.UploadInput{
|
||||
Bucket: &resp.Data.Bucket,
|
||||
Key: &resp.Data.Object,
|
||||
Body: read,
|
||||
}
|
||||
_, err = uploader.Upload(input)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
url := fmt.Sprintf("https://jayce.api.mediatrack.cn/v3/assets/%s/children", parentFile.Id)
|
||||
h := md5.New()
|
||||
_, err = io.Copy(h, &buf)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
hash := hex.EncodeToString(h.Sum(nil))
|
||||
data := base.Json{
|
||||
"category": 0,
|
||||
"description": file.GetFileName(),
|
||||
"hash": hash,
|
||||
"mime": file.MIMEType,
|
||||
"size": file.GetSize(),
|
||||
"src": src,
|
||||
"title": file.GetFileName(),
|
||||
"type": 0,
|
||||
}
|
||||
_, err = driver.Request(url, base.Post, nil, nil, nil, data, nil, account)
|
||||
return err
|
||||
}
|
||||
|
||||
var _ base.Driver = (*MediaTrack)(nil)
|
181
drivers/mediatrack/mediatrack.go
Normal file
181
drivers/mediatrack/mediatrack.go
Normal file
@ -0,0 +1,181 @@
|
||||
package mediatrack
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"github.com/Xhofe/alist/conf"
|
||||
"github.com/Xhofe/alist/drivers/base"
|
||||
"github.com/Xhofe/alist/model"
|
||||
"github.com/Xhofe/alist/utils"
|
||||
"github.com/go-resty/resty/v2"
|
||||
"path"
|
||||
"strconv"
|
||||
"time"
|
||||
)
|
||||
|
||||
type BaseResp struct {
|
||||
Status string `json:"status"`
|
||||
Message string `json:"message"`
|
||||
}
|
||||
|
||||
type T struct {
|
||||
BaseResp
|
||||
}
|
||||
|
||||
func (driver MediaTrack) Request(url string, method int, headers, query, form map[string]string, data interface{}, resp interface{}, account *model.Account) ([]byte, error) {
|
||||
req := base.RestyClient.R()
|
||||
req.SetHeader("Authorization", "Bearer "+account.AccessToken)
|
||||
if headers != nil {
|
||||
req.SetHeaders(headers)
|
||||
}
|
||||
if query != nil {
|
||||
req.SetQueryParams(query)
|
||||
}
|
||||
if form != nil {
|
||||
req.SetFormData(form)
|
||||
}
|
||||
if data != nil {
|
||||
req.SetBody(data)
|
||||
}
|
||||
var e BaseResp
|
||||
req.SetResult(&e)
|
||||
var err error
|
||||
var res *resty.Response
|
||||
switch method {
|
||||
case base.Get:
|
||||
res, err = req.Get(url)
|
||||
case base.Post:
|
||||
res, err = req.Post(url)
|
||||
case base.Delete:
|
||||
res, err = req.Delete(url)
|
||||
case base.Patch:
|
||||
res, err = req.Patch(url)
|
||||
case base.Put:
|
||||
res, err = req.Put(url)
|
||||
default:
|
||||
return nil, base.ErrNotSupport
|
||||
}
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if e.Status != "SUCCESS" {
|
||||
return nil, errors.New(e.Message)
|
||||
}
|
||||
if resp != nil {
|
||||
err = utils.Json.Unmarshal(res.Body(), resp)
|
||||
}
|
||||
return res.Body(), err
|
||||
}
|
||||
|
||||
type File struct {
|
||||
Category int `json:"category"`
|
||||
ChildAssets []interface{} `json:"childAssets"`
|
||||
CommentCount int `json:"comment_count"`
|
||||
CoverAsset interface{} `json:"cover_asset"`
|
||||
CoverAssetID string `json:"cover_asset_id"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
DeletedAt string `json:"deleted_at"`
|
||||
Description string `json:"description"`
|
||||
File *struct {
|
||||
Cover string `json:"cover"`
|
||||
Src string `json:"src"`
|
||||
} `json:"file"`
|
||||
//FileID string `json:"file_id"`
|
||||
ID string `json:"id"`
|
||||
|
||||
Size string `json:"size"`
|
||||
Thumbnails []interface{} `json:"thumbnails"`
|
||||
Title string `json:"title"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
}
|
||||
|
||||
func (driver MediaTrack) formatFile(file *File) *model.File {
|
||||
f := model.File{
|
||||
Id: file.ID,
|
||||
Name: file.Title,
|
||||
Size: 0,
|
||||
Driver: driver.Config().Name,
|
||||
UpdatedAt: &file.UpdatedAt,
|
||||
}
|
||||
if file.File == nil {
|
||||
// folder
|
||||
f.Type = conf.FOLDER
|
||||
} else {
|
||||
size, _ := strconv.ParseInt(file.Size, 10, 64)
|
||||
f.Size = size
|
||||
f.Type = utils.GetFileType(path.Ext(file.Title))
|
||||
if file.File.Cover != "" {
|
||||
f.Thumbnail = "https://nano.mtres.cn/" + file.File.Cover
|
||||
}
|
||||
}
|
||||
return &f
|
||||
}
|
||||
|
||||
type ChildrenResp struct {
|
||||
Status string `json:"status"`
|
||||
Data struct {
|
||||
Total int `json:"total"`
|
||||
Assets []File `json:"assets"`
|
||||
} `json:"data"`
|
||||
Path string `json:"path"`
|
||||
TraceID string `json:"trace_id"`
|
||||
RequestID string `json:"requestId"`
|
||||
}
|
||||
|
||||
func (driver MediaTrack) GetFiles(parentId string, account *model.Account) ([]model.File, error) {
|
||||
files := make([]model.File, 0)
|
||||
url := fmt.Sprintf("https://jayce.api.mediatrack.cn/v4/assets/%s/children", parentId)
|
||||
sort := ""
|
||||
if account.OrderBy != "" {
|
||||
if account.OrderDirection == "true" {
|
||||
sort = "-"
|
||||
}
|
||||
sort += account.OrderBy
|
||||
}
|
||||
page := 1
|
||||
for {
|
||||
var resp ChildrenResp
|
||||
_, err := driver.Request(url, base.Get, nil, map[string]string{
|
||||
"page": strconv.Itoa(page),
|
||||
"size": "50",
|
||||
"sort": sort,
|
||||
}, nil, nil, &resp, account)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if len(resp.Data.Assets) == 0 {
|
||||
break
|
||||
}
|
||||
page++
|
||||
for _, file := range resp.Data.Assets {
|
||||
files = append(files, *driver.formatFile(&file))
|
||||
}
|
||||
}
|
||||
return files, nil
|
||||
}
|
||||
|
||||
type UploadResp struct {
|
||||
Status string `json:"status"`
|
||||
Data struct {
|
||||
Credentials struct {
|
||||
TmpSecretID string `json:"TmpSecretId"`
|
||||
TmpSecretKey string `json:"TmpSecretKey"`
|
||||
Token string `json:"Token"`
|
||||
ExpiredTime int `json:"ExpiredTime"`
|
||||
Expiration time.Time `json:"Expiration"`
|
||||
StartTime int `json:"StartTime"`
|
||||
} `json:"credentials"`
|
||||
Object string `json:"object"`
|
||||
Bucket string `json:"bucket"`
|
||||
Region string `json:"region"`
|
||||
URL string `json:"url"`
|
||||
Size string `json:"size"`
|
||||
} `json:"data"`
|
||||
Path string `json:"path"`
|
||||
TraceID string `json:"trace_id"`
|
||||
RequestID string `json:"requestId"`
|
||||
}
|
||||
|
||||
func init() {
|
||||
base.RegisterDriver(&MediaTrack{})
|
||||
}
|
@ -164,6 +164,10 @@ func (driver Native) Move(src string, dst string, account *model.Account) error
|
||||
return os.Rename(fullSrc, fullDst)
|
||||
}
|
||||
|
||||
func (driver Native) Rename(src string, dst string, account *model.Account) error {
|
||||
return driver.Move(src, dst, account)
|
||||
}
|
||||
|
||||
func (driver Native) Copy(src string, dst string, account *model.Account) error {
|
||||
fullSrc := filepath.Join(account.RootFolder, src)
|
||||
fullDst := filepath.Join(account.RootFolder, dst)
|
||||
|
@ -218,14 +218,10 @@ func (driver Onedrive) MakeDir(path string, account *model.Account) error {
|
||||
"@microsoft.graph.conflictBehavior": "rename",
|
||||
}
|
||||
_, err := driver.Request(url, base.Post, nil, nil, nil, &data, nil, account)
|
||||
if err == nil {
|
||||
_ = base.DeleteCache(utils.Dir(path), account)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func (driver Onedrive) Move(src string, dst string, account *model.Account) error {
|
||||
log.Debugf("onedrive move")
|
||||
dstParentFile, err := driver.GetFile(account, utils.Dir(dst))
|
||||
if err != nil {
|
||||
return err
|
||||
@ -238,15 +234,13 @@ func (driver Onedrive) Move(src string, dst string, account *model.Account) erro
|
||||
}
|
||||
url := driver.GetMetaUrl(account, false, src)
|
||||
_, err = driver.Request(url, base.Patch, nil, nil, nil, &data, nil, account)
|
||||
if err == nil {
|
||||
_ = base.DeleteCache(utils.Dir(src), account)
|
||||
if utils.Dir(src) != utils.Dir(dst) {
|
||||
_ = base.DeleteCache(utils.Dir(dst), account)
|
||||
}
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func (driver Onedrive) Rename(src string, dst string, account *model.Account) error {
|
||||
return driver.Move(src, dst, account)
|
||||
}
|
||||
|
||||
func (driver Onedrive) Copy(src string, dst string, account *model.Account) error {
|
||||
dstParentFile, err := driver.GetFile(account, utils.Dir(dst))
|
||||
if err != nil {
|
||||
@ -261,21 +255,12 @@ func (driver Onedrive) Copy(src string, dst string, account *model.Account) erro
|
||||
}
|
||||
url := driver.GetMetaUrl(account, false, src) + "/copy"
|
||||
_, err = driver.Request(url, base.Post, nil, nil, nil, &data, nil, account)
|
||||
if err == nil {
|
||||
_ = base.DeleteCache(utils.Dir(src), account)
|
||||
if utils.Dir(src) != utils.Dir(dst) {
|
||||
_ = base.DeleteCache(utils.Dir(dst), account)
|
||||
}
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func (driver Onedrive) Delete(path string, account *model.Account) error {
|
||||
url := driver.GetMetaUrl(account, false, path)
|
||||
_, err := driver.Request(url, base.Delete, nil, nil, nil, nil, nil, account)
|
||||
if err == nil {
|
||||
_ = base.DeleteCache(utils.Dir(path), account)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
@ -289,9 +274,6 @@ func (driver Onedrive) Upload(file *model.FileStream, account *model.Account) er
|
||||
} else {
|
||||
err = driver.UploadBig(file, account)
|
||||
}
|
||||
if err == nil {
|
||||
_ = base.DeleteCache(utils.Dir(file.ParentPath), account)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
|
62
drivers/operate/operate.go
Normal file
62
drivers/operate/operate.go
Normal file
@ -0,0 +1,62 @@
|
||||
package operate
|
||||
|
||||
import (
|
||||
"github.com/Xhofe/alist/drivers/base"
|
||||
"github.com/Xhofe/alist/model"
|
||||
"github.com/Xhofe/alist/utils"
|
||||
)
|
||||
|
||||
func MakeDir(driver base.Driver, account *model.Account, path string, clearCache bool) error {
|
||||
err := driver.MakeDir(path, account)
|
||||
if err == nil && clearCache {
|
||||
_ = base.DeleteCache(utils.Dir(path), account)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func Move(driver base.Driver, account *model.Account, src, dst string, clearCache bool) error {
|
||||
rename := false
|
||||
if utils.Dir(src) == utils.Dir(dst) {
|
||||
rename = true
|
||||
}
|
||||
var err error
|
||||
if rename {
|
||||
err = driver.Rename(src, dst, account)
|
||||
} else {
|
||||
err = driver.Move(src, dst, account)
|
||||
}
|
||||
if err == nil && clearCache {
|
||||
_ = base.DeleteCache(utils.Dir(src), account)
|
||||
if !rename {
|
||||
_ = base.DeleteCache(utils.Dir(dst), account)
|
||||
}
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func Copy(driver base.Driver, account *model.Account, src, dst string, clearCache bool) error {
|
||||
err := driver.Copy(src, dst, account)
|
||||
if err == nil && clearCache {
|
||||
_ = base.DeleteCache(utils.Dir(dst), account)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func Delete(driver base.Driver, account *model.Account, path string, clearCache bool) error {
|
||||
err := driver.Delete(path, account)
|
||||
if err == nil && clearCache {
|
||||
_ = base.DeleteCache(utils.Dir(path), account)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func Upload(driver base.Driver, account *model.Account, file *model.FileStream, clearCache bool) error {
|
||||
defer func() {
|
||||
_ = file.Close()
|
||||
}()
|
||||
err := driver.Upload(file, account)
|
||||
if err == nil && clearCache {
|
||||
_ = base.DeleteCache(file.ParentPath, account)
|
||||
}
|
||||
return err
|
||||
}
|
@ -6,7 +6,10 @@ import (
|
||||
"github.com/Xhofe/alist/drivers/base"
|
||||
"github.com/Xhofe/alist/model"
|
||||
"github.com/Xhofe/alist/utils"
|
||||
"github.com/aliyun/aliyun-oss-go-sdk/oss"
|
||||
"github.com/aws/aws-sdk-go/aws"
|
||||
"github.com/aws/aws-sdk-go/aws/credentials"
|
||||
"github.com/aws/aws-sdk-go/aws/session"
|
||||
"github.com/aws/aws-sdk-go/service/s3/s3manager"
|
||||
"github.com/gin-gonic/gin"
|
||||
jsoniter "github.com/json-iterator/go"
|
||||
log "github.com/sirupsen/logrus"
|
||||
@ -159,41 +162,37 @@ func (driver PikPak) MakeDir(path string, account *model.Account) error {
|
||||
"parent_id": parentFile.Id,
|
||||
"name": name,
|
||||
}, nil, account)
|
||||
if err == nil {
|
||||
_ = base.DeleteCache(dir, account)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func (driver PikPak) Move(src string, dst string, account *model.Account) error {
|
||||
srcDir, _ := filepath.Split(src)
|
||||
dstDir, dstName := filepath.Split(dst)
|
||||
dstDir, _ := filepath.Split(dst)
|
||||
srcFile, err := driver.File(src, account)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
// rename
|
||||
if srcDir == dstDir {
|
||||
_, err = driver.Request("https://api-drive.mypikpak.com/drive/v1/files/"+srcFile.Id, base.Patch, nil, &base.Json{
|
||||
"name": dstName,
|
||||
}, nil, account)
|
||||
} else {
|
||||
// move
|
||||
dstDirFile, err := driver.File(dstDir, account)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, err = driver.Request("https://api-drive.mypikpak.com/drive/v1/files:batchMove", base.Post, nil, &base.Json{
|
||||
"ids": []string{srcFile.Id},
|
||||
"to": base.Json{
|
||||
"parent_id": dstDirFile.Id,
|
||||
},
|
||||
}, nil, account)
|
||||
dstDirFile, err := driver.File(dstDir, account)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if err == nil {
|
||||
_ = base.DeleteCache(srcDir, account)
|
||||
_ = base.DeleteCache(dstDir, account)
|
||||
_, err = driver.Request("https://api-drive.mypikpak.com/drive/v1/files:batchMove", base.Post, nil, &base.Json{
|
||||
"ids": []string{srcFile.Id},
|
||||
"to": base.Json{
|
||||
"parent_id": dstDirFile.Id,
|
||||
},
|
||||
}, nil, account)
|
||||
return err
|
||||
}
|
||||
|
||||
func (driver PikPak) Rename(src string, dst string, account *model.Account) error {
|
||||
_, dstName := filepath.Split(dst)
|
||||
srcFile, err := driver.File(src, account)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, err = driver.Request("https://api-drive.mypikpak.com/drive/v1/files/"+srcFile.Id, base.Patch, nil, &base.Json{
|
||||
"name": dstName,
|
||||
}, nil, account)
|
||||
return err
|
||||
}
|
||||
|
||||
@ -212,9 +211,6 @@ func (driver PikPak) Copy(src string, dst string, account *model.Account) error
|
||||
"parent_id": dstDirFile.Id,
|
||||
},
|
||||
}, nil, account)
|
||||
if err == nil {
|
||||
_ = base.DeleteCache(utils.Dir(dst), account)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
@ -226,9 +222,6 @@ func (driver PikPak) Delete(path string, account *model.Account) error {
|
||||
_, err = driver.Request("https://api-drive.mypikpak.com/drive/v1/files:batchTrash", base.Post, nil, &base.Json{
|
||||
"ids": []string{file.Id},
|
||||
}, nil, account)
|
||||
if err == nil {
|
||||
_ = base.DeleteCache(utils.Dir(path), account)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
@ -260,24 +253,71 @@ func (driver PikPak) Upload(file *model.FileStream, account *model.Account) erro
|
||||
accessKeyId := params.Get("access_key_id").ToString()
|
||||
accessKeySecret := params.Get("access_key_secret").ToString()
|
||||
securityToken := params.Get("security_token").ToString()
|
||||
client, err := oss.New("https://"+endpoint, accessKeyId,
|
||||
accessKeySecret, oss.SecurityToken(securityToken))
|
||||
key := params.Get("key").ToString()
|
||||
bucket := params.Get("bucket").ToString()
|
||||
cfg := &aws.Config{
|
||||
Credentials: credentials.NewStaticCredentials(accessKeyId, accessKeySecret, securityToken),
|
||||
Region: aws.String("pikpak"),
|
||||
Endpoint: &endpoint,
|
||||
}
|
||||
s, err := session.NewSession(cfg)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
bucket, err := client.Bucket(params.Get("bucket").ToString())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
signedURL, err := bucket.SignURL(params.Get("key").ToString(), oss.HTTPPut, 60)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = bucket.PutObjectWithURL(signedURL, file)
|
||||
if err == nil {
|
||||
_ = base.DeleteCache(file.ParentPath, account)
|
||||
uploader := s3manager.NewUploader(s)
|
||||
input := &s3manager.UploadInput{
|
||||
Bucket: &bucket,
|
||||
Key: &key,
|
||||
Body: file,
|
||||
}
|
||||
_, err = uploader.Upload(input)
|
||||
return err
|
||||
}
|
||||
|
||||
// use aliyun-oss-sdk
|
||||
//func (driver PikPak) Upload(file *model.FileStream, account *model.Account) error {
|
||||
// if file == nil {
|
||||
// return base.ErrEmptyFile
|
||||
// }
|
||||
// parentFile, err := driver.File(file.ParentPath, account)
|
||||
// if err != nil {
|
||||
// return err
|
||||
// }
|
||||
// data := base.Json{
|
||||
// "kind": "drive#file",
|
||||
// "name": file.GetFileName(),
|
||||
// "size": file.GetSize(),
|
||||
// "hash": "1CF254FBC456E1B012CD45C546636AA62CF8350E",
|
||||
// "upload_type": "UPLOAD_TYPE_RESUMABLE",
|
||||
// "objProvider": base.Json{"provider": "UPLOAD_TYPE_UNKNOWN"},
|
||||
// "parent_id": parentFile.Id,
|
||||
// }
|
||||
// res, err := driver.Request("https://api-drive.mypikpak.com/drive/v1/files", base.Post, nil, &data, nil, account)
|
||||
// if err != nil {
|
||||
// return err
|
||||
// }
|
||||
// params := jsoniter.Get(res, "resumable").Get("params")
|
||||
// endpoint := params.Get("endpoint").ToString()
|
||||
// endpointS := strings.Split(endpoint, ".")
|
||||
// endpoint = strings.Join(endpointS[1:], ".")
|
||||
// accessKeyId := params.Get("access_key_id").ToString()
|
||||
// accessKeySecret := params.Get("access_key_secret").ToString()
|
||||
// securityToken := params.Get("security_token").ToString()
|
||||
// client, err := oss.New("https://"+endpoint, accessKeyId,
|
||||
// accessKeySecret, oss.SecurityToken(securityToken))
|
||||
// if err != nil {
|
||||
// return err
|
||||
// }
|
||||
// bucket, err := client.Bucket(params.Get("bucket").ToString())
|
||||
// if err != nil {
|
||||
// return err
|
||||
// }
|
||||
// signedURL, err := bucket.SignURL(params.Get("key").ToString(), oss.HTTPPut, 60)
|
||||
// if err != nil {
|
||||
// return err
|
||||
// }
|
||||
// err = bucket.PutObjectWithURL(signedURL, file)
|
||||
// return err
|
||||
//}
|
||||
|
||||
var _ base.Driver = (*PikPak)(nil)
|
||||
|
@ -193,6 +193,10 @@ func (driver S3) Move(src string, dst string, account *model.Account) error {
|
||||
return driver.Delete(src, account)
|
||||
}
|
||||
|
||||
func (driver S3) Rename(src string, dst string, account *model.Account) error {
|
||||
return driver.Move(src, dst, account)
|
||||
}
|
||||
|
||||
func (driver S3) Copy(src string, dst string, account *model.Account) error {
|
||||
client, err := driver.GetClient(account)
|
||||
if err != nil {
|
||||
@ -210,9 +214,6 @@ func (driver S3) Copy(src string, dst string, account *model.Account) error {
|
||||
Key: &dstKey,
|
||||
}
|
||||
_, err = client.CopyObject(input)
|
||||
if err == nil {
|
||||
_ = base.DeleteCache(dst, account)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
@ -231,9 +232,6 @@ func (driver S3) Delete(path string, account *model.Account) error {
|
||||
Key: &key,
|
||||
}
|
||||
_, err = client.DeleteObject(input)
|
||||
if err == nil {
|
||||
_ = base.DeleteCache(utils.Dir(path), account)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
@ -253,9 +251,6 @@ func (driver S3) Upload(file *model.FileStream, account *model.Account) error {
|
||||
Body: file,
|
||||
}
|
||||
_, err := uploader.Upload(input)
|
||||
if err == nil {
|
||||
_ = base.DeleteCache(file.ParentPath, account)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
|
@ -169,9 +169,6 @@ func (driver Shandian) MakeDir(path string, account *model.Account) error {
|
||||
"name": utils.Base(path),
|
||||
}
|
||||
_, err = driver.Post("https://shandianpan.com/api/pan/mkdir", data, nil, account)
|
||||
if err == nil {
|
||||
_ = base.DeleteCache(utils.Dir(path), account)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
@ -180,30 +177,28 @@ func (driver Shandian) Move(src string, dst string, account *model.Account) erro
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if utils.Dir(src) == utils.Dir(dst) {
|
||||
// rename
|
||||
data := map[string]interface{}{
|
||||
"id": srcFile.Id,
|
||||
"name": utils.Base(dst),
|
||||
}
|
||||
_, err = driver.Post("https://shandianpan.com/api/pan/change", data, nil, account)
|
||||
} else {
|
||||
dstParentFile, err := driver.File(utils.Dir(dst), account)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
data := map[string]interface{}{
|
||||
"id": srcFile.Id,
|
||||
"to_id": dstParentFile.Id,
|
||||
}
|
||||
_, err = driver.Post("https://shandianpan.com/api/pan/move", data, nil, account)
|
||||
dstParentFile, err := driver.File(utils.Dir(dst), account)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if err == nil {
|
||||
_ = base.DeleteCache(utils.Dir(src), account)
|
||||
if utils.Dir(src) != utils.Dir(dst) {
|
||||
_ = base.DeleteCache(utils.Dir(dst), account)
|
||||
}
|
||||
data := map[string]interface{}{
|
||||
"id": srcFile.Id,
|
||||
"to_id": dstParentFile.Id,
|
||||
}
|
||||
_, err = driver.Post("https://shandianpan.com/api/pan/move", data, nil, account)
|
||||
return err
|
||||
}
|
||||
|
||||
func (driver Shandian) Rename(src string, dst string, account *model.Account) error {
|
||||
srcFile, err := driver.File(src, account)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
data := map[string]interface{}{
|
||||
"id": srcFile.Id,
|
||||
"name": utils.Base(dst),
|
||||
}
|
||||
_, err = driver.Post("https://shandianpan.com/api/pan/change", data, nil, account)
|
||||
return err
|
||||
}
|
||||
|
||||
@ -220,9 +215,6 @@ func (driver Shandian) Delete(path string, account *model.Account) error {
|
||||
"id": file.Id,
|
||||
}
|
||||
_, err = driver.Post("https://shandianpan.com/api/pan/recycle-in", data, nil, account)
|
||||
if err == nil {
|
||||
_ = base.DeleteCache(utils.Dir(path), account)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
@ -243,7 +235,11 @@ func (driver Shandian) Upload(file *model.FileStream, account *model.Account) er
|
||||
"id": parentId,
|
||||
"name": file.GetFileName(),
|
||||
}
|
||||
_, err = driver.Post("https://shandianpan.com/api/pan/upload", data, &resp, account)
|
||||
res, err := driver.Post("https://shandianpan.com/api/pan/upload", data, nil, account)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = utils.Json.Unmarshal(res, &resp)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -272,7 +268,6 @@ func (driver Shandian) Upload(file *model.FileStream, account *model.Account) er
|
||||
return err
|
||||
}
|
||||
if r.Code == 0 {
|
||||
_ = base.DeleteCache(file.ParentPath, account)
|
||||
return nil
|
||||
}
|
||||
return errors.New(r.Msg)
|
||||
|
255
drivers/teambition/driver.go
Normal file
255
drivers/teambition/driver.go
Normal file
@ -0,0 +1,255 @@
|
||||
package teambition
|
||||
|
||||
import (
|
||||
"github.com/Xhofe/alist/conf"
|
||||
"github.com/Xhofe/alist/drivers/base"
|
||||
"github.com/Xhofe/alist/model"
|
||||
"github.com/Xhofe/alist/utils"
|
||||
"github.com/gin-gonic/gin"
|
||||
log "github.com/sirupsen/logrus"
|
||||
"path/filepath"
|
||||
)
|
||||
|
||||
type Teambition struct{}
|
||||
|
||||
func (driver Teambition) Config() base.DriverConfig {
|
||||
return base.DriverConfig{
|
||||
Name: "Teambition",
|
||||
}
|
||||
}
|
||||
|
||||
func (driver Teambition) Items() []base.Item {
|
||||
return []base.Item{
|
||||
{
|
||||
Name: "internal_type",
|
||||
Label: "Teambition type",
|
||||
Type: base.TypeSelect,
|
||||
Required: true,
|
||||
Values: "China,International",
|
||||
},
|
||||
{
|
||||
Name: "access_token",
|
||||
Label: "Cookie",
|
||||
Type: base.TypeString,
|
||||
Required: true,
|
||||
Description: "Unknown expiration time",
|
||||
},
|
||||
{
|
||||
Name: "zone",
|
||||
Label: "Project id",
|
||||
Type: base.TypeString,
|
||||
Required: true,
|
||||
},
|
||||
{
|
||||
Name: "root_folder",
|
||||
Label: "root folder file_id",
|
||||
Type: base.TypeString,
|
||||
Required: true,
|
||||
},
|
||||
{
|
||||
Name: "order_by",
|
||||
Label: "order_by",
|
||||
Type: base.TypeSelect,
|
||||
Values: "fileName,fileSize,updated,created",
|
||||
Required: true,
|
||||
},
|
||||
{
|
||||
Name: "order_direction",
|
||||
Label: "order_direction",
|
||||
Type: base.TypeSelect,
|
||||
Values: "Asc,Desc",
|
||||
Required: true,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func (driver Teambition) Save(account *model.Account, old *model.Account) error {
|
||||
_, err := driver.Request("/api/v2/roles", base.Get, nil, nil, nil, nil, nil, account)
|
||||
return err
|
||||
}
|
||||
|
||||
func (driver Teambition) File(path string, account *model.Account) (*model.File, error) {
|
||||
path = utils.ParsePath(path)
|
||||
if path == "/" {
|
||||
return &model.File{
|
||||
Id: account.RootFolder,
|
||||
Name: account.Name,
|
||||
Size: 0,
|
||||
Type: conf.FOLDER,
|
||||
Driver: driver.Config().Name,
|
||||
UpdatedAt: account.UpdatedAt,
|
||||
}, nil
|
||||
}
|
||||
dir, name := filepath.Split(path)
|
||||
files, err := driver.Files(dir, account)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
for _, file := range files {
|
||||
if file.Name == name {
|
||||
return &file, nil
|
||||
}
|
||||
}
|
||||
return nil, base.ErrPathNotFound
|
||||
}
|
||||
|
||||
func (driver Teambition) Files(path string, account *model.Account) ([]model.File, error) {
|
||||
path = utils.ParsePath(path)
|
||||
var files []model.File
|
||||
cache, err := base.GetCache(path, account)
|
||||
if err == nil {
|
||||
files, _ = cache.([]model.File)
|
||||
} else {
|
||||
file, err := driver.File(path, account)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
files, err = driver.GetFiles(file.Id, account)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if len(files) > 0 {
|
||||
_ = base.SetCache(path, files, account)
|
||||
}
|
||||
}
|
||||
return files, nil
|
||||
}
|
||||
|
||||
func (driver Teambition) Link(args base.Args, account *model.Account) (*base.Link, error) {
|
||||
path := args.Path
|
||||
file, err := driver.File(path, account)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
url := file.Url
|
||||
res, err := base.NoRedirectClient.R().Get(url)
|
||||
if res.StatusCode() == 302 {
|
||||
url = res.Header().Get("location")
|
||||
}
|
||||
return &base.Link{Url: url}, nil
|
||||
}
|
||||
|
||||
func (driver Teambition) Path(path string, account *model.Account) (*model.File, []model.File, error) {
|
||||
path = utils.ParsePath(path)
|
||||
log.Debugf("teambition path: %s", path)
|
||||
file, err := driver.File(path, account)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
if !file.IsDir() {
|
||||
return file, nil, nil
|
||||
}
|
||||
files, err := driver.Files(path, account)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
return nil, files, nil
|
||||
}
|
||||
|
||||
func (driver Teambition) Proxy(c *gin.Context, account *model.Account) {
|
||||
|
||||
}
|
||||
|
||||
func (driver Teambition) Preview(path string, account *model.Account) (interface{}, error) {
|
||||
return nil, base.ErrNotSupport
|
||||
}
|
||||
|
||||
func (driver Teambition) MakeDir(path string, account *model.Account) error {
|
||||
parentFile, err := driver.File(utils.Dir(path), account)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
data := base.Json{
|
||||
"objectType": "collection",
|
||||
"_projectId": account.Zone,
|
||||
"_creatorId": "",
|
||||
"created": "",
|
||||
"updated": "",
|
||||
"title": utils.Base(path),
|
||||
"color": "blue",
|
||||
"description": "",
|
||||
"workCount": 0,
|
||||
"collectionType": "",
|
||||
"recentWorks": []interface{}{},
|
||||
"_parentId": parentFile.Id,
|
||||
"subCount": nil,
|
||||
}
|
||||
_, err = driver.Request("/api/collections", base.Post, nil, nil, nil, &data, nil, account)
|
||||
return err
|
||||
}
|
||||
|
||||
func (driver Teambition) Move(src string, dst string, account *model.Account) error {
|
||||
srcFile, err := driver.File(src, account)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
dstParentFile, err := driver.File(utils.Dir(dst), account)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
pre := "/api/works/"
|
||||
if srcFile.IsDir() {
|
||||
pre = "/api/collections/"
|
||||
}
|
||||
_, err = driver.Request(pre+srcFile.Id+"/move", base.Put, nil, nil, nil, &base.Json{
|
||||
"_parentId": dstParentFile.Id,
|
||||
}, nil, account)
|
||||
return err
|
||||
}
|
||||
|
||||
func (driver Teambition) Rename(src string, dst string, account *model.Account) error {
|
||||
srcFile, err := driver.File(src, account)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
pre := "/api/works/"
|
||||
data := base.Json{
|
||||
"fileName": utils.Base(dst),
|
||||
}
|
||||
if srcFile.IsDir() {
|
||||
pre = "/api/collections/"
|
||||
data = base.Json{
|
||||
"title": utils.Base(dst),
|
||||
}
|
||||
}
|
||||
_, err = driver.Request(pre+srcFile.Id, base.Put, nil, nil, nil, &data, nil, account)
|
||||
return err
|
||||
}
|
||||
|
||||
func (driver Teambition) Copy(src string, dst string, account *model.Account) error {
|
||||
srcFile, err := driver.File(src, account)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
dstParentFile, err := driver.File(utils.Dir(dst), account)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
pre := "/api/works/"
|
||||
if srcFile.IsDir() {
|
||||
pre = "/api/collections/"
|
||||
}
|
||||
_, err = driver.Request(pre+srcFile.Id+"/fork", base.Put, nil, nil, nil, &base.Json{
|
||||
"_parentId": dstParentFile.Id,
|
||||
}, nil, account)
|
||||
return err
|
||||
}
|
||||
|
||||
func (driver Teambition) Delete(path string, account *model.Account) error {
|
||||
srcFile, err := driver.File(path, account)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
pre := "/api/works/"
|
||||
if srcFile.IsDir() {
|
||||
pre = "/api/collections/"
|
||||
}
|
||||
_, err = driver.Request(pre+srcFile.Id+"/archive", base.Post, nil, nil, nil, nil, nil, account)
|
||||
return err
|
||||
}
|
||||
|
||||
func (driver Teambition) Upload(file *model.FileStream, account *model.Account) error {
|
||||
return base.ErrNotImplement
|
||||
}
|
||||
|
||||
var _ base.Driver = (*Teambition)(nil)
|
156
drivers/teambition/teambition.go
Normal file
156
drivers/teambition/teambition.go
Normal file
@ -0,0 +1,156 @@
|
||||
package teambition
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"github.com/Xhofe/alist/conf"
|
||||
"github.com/Xhofe/alist/drivers/base"
|
||||
"github.com/Xhofe/alist/model"
|
||||
"github.com/Xhofe/alist/utils"
|
||||
"github.com/go-resty/resty/v2"
|
||||
"path"
|
||||
"strconv"
|
||||
"time"
|
||||
)
|
||||
|
||||
type ErrResp struct {
|
||||
Name string `json:"name"`
|
||||
Message string `json:"message"`
|
||||
}
|
||||
|
||||
func (driver Teambition) Request(pathname string, method int, headers, query, form map[string]string, data interface{}, resp interface{}, account *model.Account) ([]byte, error) {
|
||||
url := "https://www.teambition.com" + pathname
|
||||
if account.InternalType == "International" {
|
||||
url = "https://us.teambition.com" + pathname
|
||||
}
|
||||
req := base.RestyClient.R()
|
||||
req.SetHeader("Cookie", account.AccessToken)
|
||||
if headers != nil {
|
||||
req.SetHeaders(headers)
|
||||
}
|
||||
if query != nil {
|
||||
req.SetQueryParams(query)
|
||||
}
|
||||
if form != nil {
|
||||
req.SetFormData(form)
|
||||
}
|
||||
if data != nil {
|
||||
req.SetBody(data)
|
||||
}
|
||||
if resp != nil {
|
||||
req.SetResult(resp)
|
||||
}
|
||||
var e ErrResp
|
||||
var err error
|
||||
var res *resty.Response
|
||||
req.SetError(&e)
|
||||
switch method {
|
||||
case base.Get:
|
||||
res, err = req.Get(url)
|
||||
case base.Post:
|
||||
res, err = req.Post(url)
|
||||
case base.Delete:
|
||||
res, err = req.Delete(url)
|
||||
case base.Patch:
|
||||
res, err = req.Patch(url)
|
||||
case base.Put:
|
||||
res, err = req.Put(url)
|
||||
default:
|
||||
return nil, base.ErrNotSupport
|
||||
}
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if e.Name != "" {
|
||||
return nil, errors.New(e.Message)
|
||||
}
|
||||
return res.Body(), nil
|
||||
}
|
||||
|
||||
type Collection struct {
|
||||
ID string `json:"_id"`
|
||||
Title string `json:"title"`
|
||||
Updated time.Time `json:"updated"`
|
||||
}
|
||||
|
||||
type Work struct {
|
||||
ID string `json:"_id"`
|
||||
FileName string `json:"fileName"`
|
||||
FileSize int64 `json:"fileSize"`
|
||||
FileKey string `json:"fileKey"`
|
||||
FileCategory string `json:"fileCategory"`
|
||||
DownloadURL string `json:"downloadUrl"`
|
||||
ThumbnailURL string `json:"thumbnailUrl"`
|
||||
Thumbnail string `json:"thumbnail"`
|
||||
Updated time.Time `json:"updated"`
|
||||
PreviewURL string `json:"previewUrl"`
|
||||
}
|
||||
|
||||
func (driver Teambition) GetFiles(parentId string, account *model.Account) ([]model.File, error) {
|
||||
files := make([]model.File, 0)
|
||||
page := 1
|
||||
for {
|
||||
var collections []Collection
|
||||
_, err := driver.Request("/api/collections", base.Get, nil, map[string]string{
|
||||
"_parentId": parentId,
|
||||
"_projectId": account.Zone,
|
||||
"order": account.OrderBy + account.OrderDirection,
|
||||
"count": "50",
|
||||
"page": strconv.Itoa(page),
|
||||
}, nil, nil, &collections, account)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if len(collections) == 0 {
|
||||
break
|
||||
}
|
||||
page++
|
||||
for _, collection := range collections {
|
||||
if collection.Title == "" {
|
||||
continue
|
||||
}
|
||||
files = append(files, model.File{
|
||||
Id: collection.ID,
|
||||
Name: collection.Title,
|
||||
Size: 0,
|
||||
Type: conf.FOLDER,
|
||||
Driver: driver.Config().Name,
|
||||
UpdatedAt: &collection.Updated,
|
||||
})
|
||||
}
|
||||
}
|
||||
page = 1
|
||||
for {
|
||||
var works []Work
|
||||
_, err := driver.Request("/api/works", base.Get, nil, map[string]string{
|
||||
"_parentId": parentId,
|
||||
"_projectId": account.Zone,
|
||||
"order": account.OrderBy + account.OrderDirection,
|
||||
"count": "50",
|
||||
"page": strconv.Itoa(page),
|
||||
}, nil, nil, &works, account)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if len(works) == 0 {
|
||||
break
|
||||
}
|
||||
page++
|
||||
for _, work := range works {
|
||||
files = append(files, model.File{
|
||||
Id: work.ID,
|
||||
Name: work.FileName,
|
||||
Size: work.FileSize,
|
||||
Type: utils.GetFileType(path.Ext(work.FileName)),
|
||||
Driver: driver.Config().Name,
|
||||
UpdatedAt: &work.Updated,
|
||||
Thumbnail: work.Thumbnail,
|
||||
Url: work.DownloadURL,
|
||||
})
|
||||
}
|
||||
}
|
||||
return files, nil
|
||||
}
|
||||
|
||||
func init() {
|
||||
base.RegisterDriver(&Teambition{})
|
||||
}
|
@ -145,39 +145,28 @@ func (driver WebDav) Preview(path string, account *model.Account) (interface{},
|
||||
func (driver WebDav) MakeDir(path string, account *model.Account) error {
|
||||
c := driver.NewClient(account)
|
||||
err := c.MkdirAll(driver.WebDavPath(path), 0644)
|
||||
if err == nil {
|
||||
_ = base.DeleteCache(utils.Dir(path), account)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func (driver WebDav) Move(src string, dst string, account *model.Account) error {
|
||||
c := driver.NewClient(account)
|
||||
err := c.Rename(driver.WebDavPath(src), driver.WebDavPath(dst), true)
|
||||
if err == nil {
|
||||
_ = base.DeleteCache(utils.Dir(src), account)
|
||||
if utils.Dir(src) != utils.Dir(dst) {
|
||||
_ = base.DeleteCache(utils.Dir(dst), account)
|
||||
}
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func (driver WebDav) Rename(src string, dst string, account *model.Account) error {
|
||||
return driver.Move(src, dst, account)
|
||||
}
|
||||
|
||||
func (driver WebDav) Copy(src string, dst string, account *model.Account) error {
|
||||
c := driver.NewClient(account)
|
||||
err := c.Copy(driver.WebDavPath(src), driver.WebDavPath(dst), true)
|
||||
if err == nil {
|
||||
_ = base.DeleteCache(utils.Dir(dst), account)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func (driver WebDav) Delete(path string, account *model.Account) error {
|
||||
c := driver.NewClient(account)
|
||||
err := c.RemoveAll(driver.WebDavPath(path))
|
||||
if err == nil {
|
||||
_ = base.DeleteCache(utils.Dir(path), account)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
@ -188,9 +177,6 @@ func (driver WebDav) Upload(file *model.FileStream, account *model.Account) erro
|
||||
c := driver.NewClient(account)
|
||||
path := utils.Join(file.ParentPath, file.Name)
|
||||
err := c.WriteStream(driver.WebDavPath(path), file, 0644)
|
||||
if err == nil {
|
||||
_ = base.DeleteCache(utils.Dir(file.ParentPath), account)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
|
5
go.mod
5
go.mod
@ -13,6 +13,7 @@ require (
|
||||
github.com/patrickmn/go-cache v2.1.0+incompatible
|
||||
github.com/robfig/cron/v3 v3.0.0
|
||||
github.com/sirupsen/logrus v1.8.1
|
||||
github.com/studio-b12/gowebdav v0.0.0-20211109083228-3f8721cd4b6f
|
||||
golang.org/x/text v0.3.7
|
||||
gorm.io/driver/mysql v1.1.2
|
||||
gorm.io/driver/postgres v1.1.2
|
||||
@ -22,7 +23,6 @@ require (
|
||||
|
||||
require (
|
||||
github.com/XiaoMi/pegasus-go-client v0.0.0-20210427083443-f3b6b08bc4c2 // indirect
|
||||
github.com/aliyun/aliyun-oss-go-sdk v2.2.0+incompatible // indirect
|
||||
github.com/beorn7/perks v1.0.1 // indirect
|
||||
github.com/bradfitz/gomemcache v0.0.0-20190913173617-a41fca850d0b // indirect
|
||||
github.com/cenkalti/backoff/v4 v4.1.0 // indirect
|
||||
@ -35,6 +35,7 @@ require (
|
||||
github.com/go-redis/redis/v8 v8.9.0 // indirect
|
||||
github.com/go-sql-driver/mysql v1.6.0 // indirect
|
||||
github.com/golang/protobuf v1.5.2 // indirect
|
||||
github.com/google/uuid v1.3.0 // indirect
|
||||
github.com/jackc/chunkreader/v2 v2.0.1 // indirect
|
||||
github.com/jackc/pgconn v1.10.0 // indirect
|
||||
github.com/jackc/pgio v1.0.0 // indirect
|
||||
@ -58,7 +59,6 @@ require (
|
||||
github.com/prometheus/common v0.18.0 // indirect
|
||||
github.com/prometheus/procfs v0.6.0 // indirect
|
||||
github.com/spf13/cast v1.3.1 // indirect
|
||||
github.com/studio-b12/gowebdav v0.0.0-20211109083228-3f8721cd4b6f // indirect
|
||||
github.com/ugorji/go/codec v1.2.6 // indirect
|
||||
go.opentelemetry.io/otel v0.20.0 // indirect
|
||||
go.opentelemetry.io/otel/metric v0.20.0 // indirect
|
||||
@ -66,7 +66,6 @@ require (
|
||||
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519 // indirect
|
||||
golang.org/x/net v0.0.0-20211209124913-491a49abca63 // indirect
|
||||
golang.org/x/sys v0.0.0-20211023085530-d6a326fbbf70 // indirect
|
||||
golang.org/x/time v0.0.0-20191024005414-555d28b269f0 // indirect
|
||||
google.golang.org/protobuf v1.27.1 // indirect
|
||||
gopkg.in/natefinch/lumberjack.v2 v2.0.0 // indirect
|
||||
gopkg.in/tomb.v2 v2.0.0-20161208151619-d5d1b5820637 // indirect
|
||||
|
5
go.sum
5
go.sum
@ -20,8 +20,6 @@ github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751/go.mod h1:LOuy
|
||||
github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0=
|
||||
github.com/alecthomas/units v0.0.0-20190717042225-c3de453c63f4/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0=
|
||||
github.com/alecthomas/units v0.0.0-20190924025748-f65c72e2690d/go.mod h1:rBZYJk541a8SKzHPHnH3zbiI+7dagKZ0cgpgrD7Fyho=
|
||||
github.com/aliyun/aliyun-oss-go-sdk v2.2.0+incompatible h1:ht2+VfbXtNLGhCsnTMc6/N26nSTBK6qdhktjYyjJQkk=
|
||||
github.com/aliyun/aliyun-oss-go-sdk v2.2.0+incompatible/go.mod h1:T/Aws4fEfogEE9v+HPhhw+CntffsBHJ8nXQCwKr0/g8=
|
||||
github.com/allegro/bigcache/v2 v2.2.5 h1:mRc8r6GQjuJsmSKQNPsR5jQVXc8IJ1xsW5YXUYMLfqI=
|
||||
github.com/allegro/bigcache/v2 v2.2.5/go.mod h1:FppZsIO+IZk7gCuj5FiIDHGygD9xvWQcqg1uIPMb6tY=
|
||||
github.com/apache/thrift v0.12.0/go.mod h1:cp2SuWMxlEZw2r+iP2GNCdIi4C1qmUzdZFSVb+bacwQ=
|
||||
@ -184,6 +182,8 @@ github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/
|
||||
github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI=
|
||||
github.com/google/uuid v1.0.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
||||
github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
||||
github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I=
|
||||
github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
||||
github.com/googleapis/gnostic v0.0.0-20170729233727-0c5108395e2d/go.mod h1:sJBsCZ4ayReDTBIg8b9dl28c5xFWyhBTVRp3pOg5EKY=
|
||||
github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1 h1:EGx4pi6eqNxGaHF6qqu48+N2wcFQ5qg5FXgOdqsJ5d8=
|
||||
github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY=
|
||||
@ -640,7 +640,6 @@ golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||
golang.org/x/text v0.3.7 h1:olpwvP2KacW1ZWvsR7uQhoyTYvKAupfQrRGBFM352Gk=
|
||||
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
|
||||
golang.org/x/time v0.0.0-20180412165947-fbb02b2291d2/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
|
||||
golang.org/x/time v0.0.0-20191024005414-555d28b269f0 h1:/5xXl8Y5W96D+TtHSlonuFqGHIWVuyCkGJLwGh9JJFs=
|
||||
golang.org/x/time v0.0.0-20191024005414-555d28b269f0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
|
||||
golang.org/x/tools v0.0.0-20180221164845-07fd8470d635/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||
golang.org/x/tools v0.0.0-20180828015842-6cd1fcedba52/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||
|
@ -25,6 +25,14 @@ func SortFiles(files []File, account *Account) {
|
||||
return
|
||||
}
|
||||
sort.Slice(files, func(i, j int) bool {
|
||||
if files[i].IsDir() || files[j].IsDir() {
|
||||
if !files[i].IsDir() {
|
||||
return false
|
||||
}
|
||||
if !files[j].IsDir() {
|
||||
return true
|
||||
}
|
||||
}
|
||||
switch account.OrderBy {
|
||||
case "name":
|
||||
{
|
||||
|
@ -93,51 +93,34 @@ func LoadSettings() {
|
||||
if err == nil {
|
||||
conf.TextTypes = strings.Split(textTypes.Value, ",")
|
||||
}
|
||||
checkParent, err := GetSettingByKey("check parent folder")
|
||||
if err == nil {
|
||||
conf.CheckParent = checkParent.Value == "true"
|
||||
}
|
||||
checkDown, err := GetSettingByKey("check down link")
|
||||
if err == nil {
|
||||
conf.CheckDown = checkDown.Value == "true"
|
||||
}
|
||||
// html
|
||||
favicon, err := GetSettingByKey("favicon")
|
||||
if err == nil {
|
||||
//conf.Favicon = favicon.Value
|
||||
conf.IndexHtml = strings.Replace(conf.RawIndexHtml, "https://store.heytapimage.com/cdo-portal/feedback/202110/30/d43c41c5d257c9bc36366e310374fb19.png", favicon.Value, 1)
|
||||
conf.ManageHtml = strings.Replace(conf.RawIndexHtml, "https://store.heytapimage.com/cdo-portal/feedback/202110/30/d43c41c5d257c9bc36366e310374fb19.png", favicon.Value, 1)
|
||||
}
|
||||
title, err := GetSettingByKey("title")
|
||||
if err == nil {
|
||||
conf.IndexHtml = strings.Replace(conf.IndexHtml, "Loading...", title.Value, 1)
|
||||
conf.ManageHtml = strings.Replace(conf.ManageHtml, "Loading...", title.Value, 1)
|
||||
}
|
||||
customizeHead, err := GetSettingByKey("customize head")
|
||||
if err == nil {
|
||||
conf.IndexHtml = strings.Replace(conf.IndexHtml, "<!-- customize head -->", customizeHead.Value, 1)
|
||||
conf.IndexHtml = strings.Replace(conf.ManageHtml, "<!-- customize head -->", customizeHead.Value, 1)
|
||||
}
|
||||
customizeBody, err := GetSettingByKey("customize body")
|
||||
if err == nil {
|
||||
conf.IndexHtml = strings.Replace(conf.IndexHtml, "<!-- customize body -->", customizeBody.Value, 1)
|
||||
}
|
||||
|
||||
// token
|
||||
adminPassword, err := GetSettingByKey("password")
|
||||
if err == nil {
|
||||
conf.Token = utils.GetMD5Encode(fmt.Sprintf("https://github.com/Xhofe/alist-%s", adminPassword.Value))
|
||||
}
|
||||
|
||||
davUsername, err := GetSettingByKey("WebDAV username")
|
||||
if err == nil {
|
||||
conf.DavUsername = davUsername.Value
|
||||
}
|
||||
davPassword, err := GetSettingByKey("WebDAV password")
|
||||
if err == nil {
|
||||
conf.DavPassword = davPassword.Value
|
||||
}
|
||||
visitorDavUsername, err := GetSettingByKey("Visitor WebDAV username")
|
||||
if err == nil {
|
||||
conf.VisitorDavUsername = visitorDavUsername.Value
|
||||
}
|
||||
visitorDavPassword, err := GetSettingByKey("Visitor WebDAV password")
|
||||
if err == nil {
|
||||
conf.VisitorDavPassword = visitorDavPassword.Value
|
||||
// load settings
|
||||
for _, key := range conf.LoadSettings {
|
||||
vm, err := GetSettingByKey(key)
|
||||
if err == nil {
|
||||
conf.Set(key, vm.Value)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -28,7 +28,7 @@ func CheckParent(path string, password string) bool {
|
||||
}
|
||||
|
||||
func CheckDownLink(path string, passwordMd5 string, name string) bool {
|
||||
if !conf.CheckDown {
|
||||
if !conf.GetBool("check down link") {
|
||||
return true
|
||||
}
|
||||
meta, err := model.GetMetaByPath(path)
|
||||
@ -40,7 +40,7 @@ func CheckDownLink(path string, passwordMd5 string, name string) bool {
|
||||
}
|
||||
return true
|
||||
} else {
|
||||
if !conf.CheckParent {
|
||||
if !conf.GetBool("check parent folder") {
|
||||
return true
|
||||
}
|
||||
if path == "/" {
|
||||
|
@ -19,6 +19,8 @@ type Resp struct {
|
||||
type PathReq struct {
|
||||
Path string `json:"path"`
|
||||
Password string `json:"password"`
|
||||
PageNum int `json:"page_num"`
|
||||
PageSize int `json:"page_size"`
|
||||
}
|
||||
|
||||
func ParsePath(rawPath string) (*model.Account, string, base.Driver, error) {
|
||||
|
@ -66,7 +66,7 @@ func Proxy(c *gin.Context) {
|
||||
}
|
||||
}
|
||||
// 中转时有中转机器使用中转机器,若携带标志位则表明不能再走中转机器了
|
||||
if account.DownProxyUrl != "" && c.Param("d") != "1" {
|
||||
if account.DownProxyUrl != "" && c.Query("d") != "1" {
|
||||
name := utils.Base(rawPath)
|
||||
link := fmt.Sprintf("%s%s?sign=%s", account.DownProxyUrl, rawPath, utils.SignWithToken(name, conf.Token))
|
||||
c.Redirect(302, link)
|
||||
|
47
server/controllers/file/delete.go
Normal file
47
server/controllers/file/delete.go
Normal file
@ -0,0 +1,47 @@
|
||||
package file
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"github.com/Xhofe/alist/drivers/base"
|
||||
"github.com/Xhofe/alist/drivers/operate"
|
||||
"github.com/Xhofe/alist/server/common"
|
||||
"github.com/Xhofe/alist/utils"
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
type DeleteFilesReq struct {
|
||||
Path string `json:"path"`
|
||||
Names []string `json:"names"`
|
||||
}
|
||||
|
||||
func DeleteFiles(c *gin.Context) {
|
||||
var req DeleteFilesReq
|
||||
if err := c.ShouldBind(&req); err != nil {
|
||||
common.ErrorResp(c, err, 400)
|
||||
return
|
||||
}
|
||||
if len(req.Names) == 0 {
|
||||
common.ErrorResp(c, errors.New("empty file names"), 400)
|
||||
return
|
||||
}
|
||||
for i, name := range req.Names {
|
||||
account, path_, driver, err := common.ParsePath(utils.Join(req.Path, name))
|
||||
if err != nil {
|
||||
common.ErrorResp(c, err, 500)
|
||||
return
|
||||
}
|
||||
clearCache := false
|
||||
if i == len(req.Names)-1 {
|
||||
clearCache = true
|
||||
}
|
||||
err = operate.Delete(driver, account, path_, clearCache)
|
||||
if err != nil {
|
||||
if i == 0 {
|
||||
_ = base.DeleteCache(utils.Dir(path_), account)
|
||||
}
|
||||
common.ErrorResp(c, err, 500)
|
||||
return
|
||||
}
|
||||
}
|
||||
common.SuccessResp(c)
|
||||
}
|
@ -1,15 +1,17 @@
|
||||
package controllers
|
||||
package file
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"github.com/Xhofe/alist/conf"
|
||||
"github.com/Xhofe/alist/drivers/base"
|
||||
"github.com/Xhofe/alist/drivers/operate"
|
||||
"github.com/Xhofe/alist/model"
|
||||
"github.com/Xhofe/alist/server/common"
|
||||
"github.com/Xhofe/alist/utils"
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
func UploadFile(c *gin.Context) {
|
||||
func UploadFiles(c *gin.Context) {
|
||||
path := c.PostForm("path")
|
||||
path = utils.ParsePath(path)
|
||||
token := c.GetHeader("Authorization")
|
||||
@ -25,33 +27,40 @@ func UploadFile(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
}
|
||||
file, err := c.FormFile("file")
|
||||
if err != nil {
|
||||
common.ErrorResp(c, err, 400)
|
||||
}
|
||||
open, err := file.Open()
|
||||
defer func() {
|
||||
_ = open.Close()
|
||||
}()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
account, path_, driver, err := common.ParsePath(path)
|
||||
if err != nil {
|
||||
common.ErrorResp(c, err, 500)
|
||||
return
|
||||
}
|
||||
fileStream := model.FileStream{
|
||||
File: open,
|
||||
Size: uint64(file.Size),
|
||||
ParentPath: path_,
|
||||
Name: file.Filename,
|
||||
MIMEType: c.GetHeader("Content-Type"),
|
||||
}
|
||||
err = driver.Upload(&fileStream, account)
|
||||
form, err := c.MultipartForm()
|
||||
if err != nil {
|
||||
common.ErrorResp(c, err, 400)
|
||||
}
|
||||
files := form.File["files"]
|
||||
if err != nil {
|
||||
common.ErrorResp(c, err, 500)
|
||||
return
|
||||
}
|
||||
for i, file := range files {
|
||||
open, err := file.Open()
|
||||
fileStream := model.FileStream{
|
||||
File: open,
|
||||
Size: uint64(file.Size),
|
||||
ParentPath: path_,
|
||||
Name: file.Filename,
|
||||
MIMEType: file.Header.Get("Content-Type"),
|
||||
}
|
||||
clearCache := false
|
||||
if i == len(files)-1 {
|
||||
clearCache = true
|
||||
}
|
||||
err = operate.Upload(driver, account, &fileStream, clearCache)
|
||||
if err != nil {
|
||||
if i != 0 {
|
||||
_ = base.DeleteCache(path_, account)
|
||||
}
|
||||
common.ErrorResp(c, err, 500)
|
||||
return
|
||||
}
|
||||
}
|
||||
common.SuccessResp(c)
|
||||
}
|
47
server/controllers/link.go
Normal file
47
server/controllers/link.go
Normal file
@ -0,0 +1,47 @@
|
||||
package controllers
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/Xhofe/alist/conf"
|
||||
"github.com/Xhofe/alist/drivers/base"
|
||||
"github.com/Xhofe/alist/server/common"
|
||||
"github.com/Xhofe/alist/utils"
|
||||
"github.com/gin-gonic/gin"
|
||||
log "github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
type LinkReq struct {
|
||||
Path string `json:"path"`
|
||||
//Password string `json:"password"`
|
||||
}
|
||||
|
||||
// Link 返回真实的链接,且携带头,只提供给中转程序使用
|
||||
func Link(c *gin.Context) {
|
||||
var req LinkReq
|
||||
if err := c.ShouldBind(&req); err != nil {
|
||||
common.ErrorResp(c, err, 400)
|
||||
return
|
||||
}
|
||||
req.Path = utils.ParsePath(req.Path)
|
||||
rawPath := req.Path
|
||||
rawPath = utils.ParsePath(rawPath)
|
||||
log.Debugf("link: %s", rawPath)
|
||||
account, path, driver, err := common.ParsePath(rawPath)
|
||||
if err != nil {
|
||||
common.ErrorResp(c, err, 500)
|
||||
return
|
||||
}
|
||||
if driver.Config().OnlyLocal {
|
||||
common.SuccessResp(c, base.Link{
|
||||
Url: fmt.Sprintf("//%s/p%s?d=1&sign=%s", c.Request.Host, req.Path, utils.SignWithToken(utils.Base(rawPath), conf.Token)),
|
||||
})
|
||||
return
|
||||
}
|
||||
link, err := driver.Link(base.Args{Path: path, IP: c.ClientIP()}, account)
|
||||
if err != nil {
|
||||
common.ErrorResp(c, err, 500)
|
||||
return
|
||||
}
|
||||
common.SuccessResp(c, link)
|
||||
return
|
||||
}
|
@ -1,6 +1,7 @@
|
||||
package controllers
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"github.com/Xhofe/alist/conf"
|
||||
"github.com/Xhofe/alist/drivers/base"
|
||||
@ -12,7 +13,7 @@ import (
|
||||
"strings"
|
||||
)
|
||||
|
||||
func Hide(meta *model.Meta, files []model.File, path string) []model.File {
|
||||
func Hide(meta *model.Meta, files []model.File) []model.File {
|
||||
//meta, _ := model.GetMetaByPath(path)
|
||||
if meta != nil && meta.Hide != "" {
|
||||
tmpFiles := make([]model.File, 0)
|
||||
@ -27,9 +28,54 @@ func Hide(meta *model.Meta, files []model.File, path string) []model.File {
|
||||
return files
|
||||
}
|
||||
|
||||
func Pagination(files []model.File, req *common.PathReq) (int, []model.File) {
|
||||
pageNum, pageSize := req.PageNum, req.PageSize
|
||||
total := len(files)
|
||||
if isAll(req) {
|
||||
return total, files
|
||||
}
|
||||
switch conf.GetStr("load type") {
|
||||
case "all":
|
||||
return total, files
|
||||
//case "pagination":
|
||||
//
|
||||
}
|
||||
start := (pageNum - 1) * pageSize
|
||||
if start > total {
|
||||
return total, []model.File{}
|
||||
}
|
||||
end := start + pageSize
|
||||
if end > total {
|
||||
end = total
|
||||
}
|
||||
return total, files[start:end]
|
||||
}
|
||||
|
||||
func isAll(req *common.PathReq) bool {
|
||||
return req.PageNum == 0 && req.PageSize == 0
|
||||
}
|
||||
|
||||
func CheckPagination(req *common.PathReq) error {
|
||||
if isAll(req) {
|
||||
return nil
|
||||
}
|
||||
if conf.GetStr("loading type") == "all" {
|
||||
return nil
|
||||
}
|
||||
if req.PageNum < 1 {
|
||||
return errors.New("page_num can't be less than 1")
|
||||
}
|
||||
if req.PageSize == 0 {
|
||||
req.PageSize = conf.GetInt("default page size", 30)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
type Meta struct {
|
||||
Driver string `json:"driver"`
|
||||
Upload bool `json:"upload"`
|
||||
Total int `json:"total"`
|
||||
//Pages int `json:"pages"`
|
||||
}
|
||||
|
||||
type PathResp struct {
|
||||
@ -52,7 +98,7 @@ func Path(c *gin.Context) {
|
||||
common.ErrorResp(c, err, 500)
|
||||
return
|
||||
}
|
||||
files = Hide(meta, files, req.Path)
|
||||
files = Hide(meta, files)
|
||||
c.JSON(200, common.Resp{
|
||||
Code: 200,
|
||||
Message: "success",
|
||||
@ -66,6 +112,11 @@ func Path(c *gin.Context) {
|
||||
})
|
||||
return
|
||||
}
|
||||
err := CheckPagination(&req)
|
||||
if err != nil {
|
||||
common.ErrorResp(c, err, 400)
|
||||
return
|
||||
}
|
||||
account, path, driver, err := common.ParsePath(req.Path)
|
||||
if err != nil {
|
||||
common.ErrorResp(c, err, 500)
|
||||
@ -104,10 +155,11 @@ func Path(c *gin.Context) {
|
||||
},
|
||||
})
|
||||
} else {
|
||||
files = Hide(meta, files, req.Path)
|
||||
files = Hide(meta, files)
|
||||
if driver.Config().LocalSort {
|
||||
model.SortFiles(files, account)
|
||||
}
|
||||
total, files := Pagination(files, &req)
|
||||
c.JSON(200, common.Resp{
|
||||
Code: 200,
|
||||
Message: "success",
|
||||
@ -116,6 +168,7 @@ func Path(c *gin.Context) {
|
||||
Meta: Meta{
|
||||
Driver: driver.Config().Name,
|
||||
Upload: upload,
|
||||
Total: total,
|
||||
},
|
||||
Files: files,
|
||||
},
|
||||
@ -123,37 +176,6 @@ func Path(c *gin.Context) {
|
||||
}
|
||||
}
|
||||
|
||||
// Link 返回真实的链接,且携带头,只提供给中转程序使用
|
||||
func Link(c *gin.Context) {
|
||||
var req common.PathReq
|
||||
if err := c.ShouldBind(&req); err != nil {
|
||||
common.ErrorResp(c, err, 400)
|
||||
return
|
||||
}
|
||||
req.Path = utils.ParsePath(req.Path)
|
||||
rawPath := req.Path
|
||||
rawPath = utils.ParsePath(rawPath)
|
||||
log.Debugf("link: %s", rawPath)
|
||||
account, path, driver, err := common.ParsePath(rawPath)
|
||||
if err != nil {
|
||||
common.ErrorResp(c, err, 500)
|
||||
return
|
||||
}
|
||||
if driver.Config().OnlyLocal {
|
||||
common.SuccessResp(c, base.Link{
|
||||
Url: fmt.Sprintf("//%s/p%s?d=1&sign=%s", c.Request.Host, req.Path, utils.SignWithToken(utils.Base(rawPath), conf.Token)),
|
||||
})
|
||||
return
|
||||
}
|
||||
link, err := driver.Link(base.Args{Path: path, IP: c.ClientIP()}, account)
|
||||
if err != nil {
|
||||
common.ErrorResp(c, err, 500)
|
||||
return
|
||||
}
|
||||
common.SuccessResp(c, link)
|
||||
return
|
||||
}
|
||||
|
||||
func Preview(c *gin.Context) {
|
||||
reqV, _ := c.Get("req")
|
||||
req := reqV.(common.PathReq)
|
||||
|
@ -16,7 +16,7 @@ func PathCheck(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
req.Path = utils.ParsePath(req.Path)
|
||||
c.Set("req",req)
|
||||
c.Set("req", req)
|
||||
token := c.GetHeader("Authorization")
|
||||
if token == conf.Token {
|
||||
c.Next()
|
||||
@ -29,7 +29,7 @@ func PathCheck(c *gin.Context) {
|
||||
c.Abort()
|
||||
return
|
||||
}
|
||||
} else if conf.CheckParent {
|
||||
} else if conf.GetBool("check parent folder") {
|
||||
if !common.CheckParent(utils.Dir(req.Path), req.Password) {
|
||||
common.ErrorResp(c, fmt.Errorf("wrong password"), 401)
|
||||
c.Abort()
|
||||
@ -37,4 +37,4 @@ func PathCheck(c *gin.Context) {
|
||||
}
|
||||
}
|
||||
c.Next()
|
||||
}
|
||||
}
|
||||
|
@ -3,6 +3,7 @@ package server
|
||||
import (
|
||||
"github.com/Xhofe/alist/server/common"
|
||||
"github.com/Xhofe/alist/server/controllers"
|
||||
"github.com/Xhofe/alist/server/controllers/file"
|
||||
"github.com/Xhofe/alist/server/middlewares"
|
||||
"github.com/gin-contrib/cors"
|
||||
"github.com/gin-gonic/gin"
|
||||
@ -23,7 +24,7 @@ func InitApiRouter(r *gin.Engine) {
|
||||
path.POST("/preview", controllers.Preview)
|
||||
|
||||
//path.POST("/link",middlewares.Auth, controllers.Link)
|
||||
public.POST("/upload", controllers.UploadFile)
|
||||
public.POST("/upload", file.UploadFiles)
|
||||
|
||||
public.GET("/settings", controllers.GetSettingsPublic)
|
||||
}
|
||||
@ -49,6 +50,7 @@ func InitApiRouter(r *gin.Engine) {
|
||||
admin.DELETE("/meta", controllers.DeleteMeta)
|
||||
|
||||
admin.POST("/link", controllers.Link)
|
||||
admin.DELETE("/files", file.DeleteFiles)
|
||||
}
|
||||
WebDav(r)
|
||||
Static(r)
|
||||
@ -57,6 +59,6 @@ func InitApiRouter(r *gin.Engine) {
|
||||
func Cors(r *gin.Engine) {
|
||||
config := cors.DefaultConfig()
|
||||
config.AllowAllOrigins = true
|
||||
config.AllowHeaders = append(config.AllowHeaders, "Authorization")
|
||||
config.AllowHeaders = append(config.AllowHeaders, "Authorization", "range")
|
||||
r.Use(cors.New(config))
|
||||
}
|
||||
|
@ -8,6 +8,7 @@ import (
|
||||
"io/fs"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func InitIndex() {
|
||||
@ -41,7 +42,11 @@ func Static(r *gin.Engine) {
|
||||
r.NoRoute(func(c *gin.Context) {
|
||||
c.Status(200)
|
||||
c.Header("Content-Type", "text/html")
|
||||
_, _ = c.Writer.WriteString(conf.IndexHtml)
|
||||
if strings.HasPrefix(c.Request.URL.Path, "/@manage") {
|
||||
_, _ = c.Writer.WriteString(conf.ManageHtml)
|
||||
} else {
|
||||
_, _ = c.Writer.WriteString(conf.IndexHtml)
|
||||
}
|
||||
c.Writer.Flush()
|
||||
c.Writer.WriteHeaderNow()
|
||||
})
|
||||
|
@ -49,11 +49,14 @@ func WebDAVAuth(c *gin.Context) {
|
||||
c.Abort()
|
||||
return
|
||||
}
|
||||
if conf.DavUsername == username && conf.DavPassword == password {
|
||||
if conf.GetStr("WebDAV username") == username && conf.GetStr("WebDAV password") == password {
|
||||
c.Next()
|
||||
return
|
||||
}
|
||||
if (conf.VisitorDavUsername == username && conf.VisitorDavPassword == password) || (conf.VisitorDavUsername == "" && conf.VisitorDavPassword == "") {
|
||||
if (conf.GetStr("Visitor WebDAV username") == username &&
|
||||
conf.GetStr("Visitor WebDAV password") == password) ||
|
||||
(conf.GetStr("Visitor WebDAV username") == "" &&
|
||||
conf.GetStr("Visitor WebDAV password") == "") {
|
||||
if !utils.IsContain([]string{"PUT", "DELETE", "PROPPATCH", "MKCOL", "COPY", "MOVE"}, c.Request.Method) {
|
||||
c.Next()
|
||||
return
|
||||
|
@ -9,7 +9,9 @@ import (
|
||||
"fmt"
|
||||
"github.com/Xhofe/alist/conf"
|
||||
"github.com/Xhofe/alist/drivers/base"
|
||||
"github.com/Xhofe/alist/drivers/operate"
|
||||
"github.com/Xhofe/alist/model"
|
||||
"github.com/Xhofe/alist/server/common"
|
||||
"github.com/Xhofe/alist/utils"
|
||||
log "github.com/sirupsen/logrus"
|
||||
"net"
|
||||
@ -22,30 +24,6 @@ import (
|
||||
|
||||
type FileSystem struct{}
|
||||
|
||||
func ParsePath(rawPath string) (*model.Account, string, base.Driver, error) {
|
||||
var internalPath, name string
|
||||
switch model.AccountsCount() {
|
||||
case 0:
|
||||
return nil, "", nil, fmt.Errorf("no accounts,please add one first")
|
||||
case 1:
|
||||
internalPath = rawPath
|
||||
break
|
||||
default:
|
||||
paths := strings.Split(rawPath, "/")
|
||||
internalPath = "/" + strings.Join(paths[2:], "/")
|
||||
name = paths[1]
|
||||
}
|
||||
account, ok := model.GetAccount(name)
|
||||
if !ok {
|
||||
return nil, "", nil, fmt.Errorf("no [%s] account", name)
|
||||
}
|
||||
driver, ok := base.GetDriver(account.Type)
|
||||
if !ok {
|
||||
return nil, "", nil, fmt.Errorf("no [%s] driver", account.Type)
|
||||
}
|
||||
return &account, internalPath, driver, nil
|
||||
}
|
||||
|
||||
func (fs *FileSystem) File(rawPath string) (*model.File, error) {
|
||||
rawPath = utils.ParsePath(rawPath)
|
||||
if model.AccountsCount() > 1 && rawPath == "/" {
|
||||
@ -58,7 +36,7 @@ func (fs *FileSystem) File(rawPath string) (*model.File, error) {
|
||||
UpdatedAt: &now,
|
||||
}, nil
|
||||
}
|
||||
account, path_, driver, err := ParsePath(rawPath)
|
||||
account, path_, driver, err := common.ParsePath(rawPath)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -74,34 +52,13 @@ func (fs *FileSystem) Files(rawPath string) ([]model.File, error) {
|
||||
}
|
||||
return files, nil
|
||||
}
|
||||
account, path_, driver, err := ParsePath(rawPath)
|
||||
account, path_, driver, err := common.ParsePath(rawPath)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return driver.Files(path_, account)
|
||||
}
|
||||
|
||||
//func GetPW(path string, name string) string {
|
||||
// if !conf.CheckDown {
|
||||
// return ""
|
||||
// }
|
||||
// meta, err := model.GetMetaByPath(path)
|
||||
// if err == nil {
|
||||
// if meta.Password != "" {
|
||||
// return utils.SignWithPassword(name, meta.Password)
|
||||
// }
|
||||
// return ""
|
||||
// } else {
|
||||
// if !conf.CheckParent {
|
||||
// return ""
|
||||
// }
|
||||
// if path == "/" {
|
||||
// return ""
|
||||
// }
|
||||
// return GetPW(utils.Dir(path), name)
|
||||
// }
|
||||
//}
|
||||
|
||||
func ClientIP(r *http.Request) string {
|
||||
xForwardedFor := r.Header.Get("X-Forwarded-For")
|
||||
ip := strings.TrimSpace(strings.Split(xForwardedFor, ",")[0])
|
||||
@ -127,7 +84,7 @@ func (fs *FileSystem) Link(r *http.Request, rawPath string) (string, error) {
|
||||
if model.AccountsCount() > 1 && rawPath == "/" {
|
||||
// error
|
||||
}
|
||||
account, path_, driver, err := ParsePath(rawPath)
|
||||
account, path_, driver, err := common.ParsePath(rawPath)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
@ -138,7 +95,7 @@ func (fs *FileSystem) Link(r *http.Request, rawPath string) (string, error) {
|
||||
}
|
||||
if driver.Config().OnlyProxy || account.WebdavProxy {
|
||||
link = fmt.Sprintf("%s://%s/p%s", protocol, r.Host, rawPath)
|
||||
if conf.CheckDown {
|
||||
if conf.GetBool("check down link") {
|
||||
sign := utils.SignWithToken(utils.Base(rawPath), conf.Token)
|
||||
link += "?sign" + sign
|
||||
}
|
||||
@ -161,12 +118,12 @@ func (fs *FileSystem) CreateDirectory(ctx context.Context, rawPath string) error
|
||||
if model.AccountsCount() > 1 && len(strings.Split(rawPath, "/")) < 2 {
|
||||
return ErrNotImplemented
|
||||
}
|
||||
account, path_, driver, err := ParsePath(rawPath)
|
||||
account, path_, driver, err := common.ParsePath(rawPath)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
log.Debugf("mkdir: %s", path_)
|
||||
return driver.MakeDir(path_, account)
|
||||
return operate.MakeDir(driver, account, path_, true)
|
||||
}
|
||||
|
||||
func (fs *FileSystem) Upload(ctx context.Context, r *http.Request, rawPath string) error {
|
||||
@ -174,7 +131,7 @@ func (fs *FileSystem) Upload(ctx context.Context, r *http.Request, rawPath strin
|
||||
if model.AccountsCount() > 1 && rawPath == "/" {
|
||||
return ErrNotImplemented
|
||||
}
|
||||
account, path_, driver, err := ParsePath(rawPath)
|
||||
account, path_, driver, err := common.ParsePath(rawPath)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -191,7 +148,7 @@ func (fs *FileSystem) Upload(ctx context.Context, r *http.Request, rawPath strin
|
||||
Name: fileName,
|
||||
ParentPath: filePath,
|
||||
}
|
||||
return driver.Upload(&fileData, account)
|
||||
return operate.Upload(driver, account, &fileData, true)
|
||||
}
|
||||
|
||||
func (fs *FileSystem) Delete(rawPath string) error {
|
||||
@ -202,11 +159,11 @@ func (fs *FileSystem) Delete(rawPath string) error {
|
||||
if model.AccountsCount() > 1 && len(strings.Split(rawPath, "/")) < 2 {
|
||||
return ErrNotImplemented
|
||||
}
|
||||
account, path_, driver, err := ParsePath(rawPath)
|
||||
account, path_, driver, err := common.ParsePath(rawPath)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return driver.Delete(path_, account)
|
||||
return operate.Delete(driver, account, path_, true)
|
||||
}
|
||||
|
||||
// slashClean is equivalent to but slightly more efficient than
|
||||
@ -228,18 +185,18 @@ func moveFiles(ctx context.Context, fs *FileSystem, src string, dst string, over
|
||||
if src == dst {
|
||||
return http.StatusMethodNotAllowed, errDestinationEqualsSource
|
||||
}
|
||||
srcAccount, srcPath, driver, err := ParsePath(src)
|
||||
srcAccount, srcPath, driver, err := common.ParsePath(src)
|
||||
if err != nil {
|
||||
return http.StatusMethodNotAllowed, err
|
||||
}
|
||||
dstAccount, dstPath, _, err := ParsePath(dst)
|
||||
dstAccount, dstPath, _, err := common.ParsePath(dst)
|
||||
if err != nil {
|
||||
return http.StatusMethodNotAllowed, err
|
||||
}
|
||||
if srcAccount.Name != dstAccount.Name {
|
||||
return http.StatusMethodNotAllowed, errInvalidDestination
|
||||
}
|
||||
err = driver.Move(srcPath, dstPath, srcAccount)
|
||||
err = operate.Move(driver, srcAccount, srcPath, dstPath, true)
|
||||
if err != nil {
|
||||
log.Debug(err)
|
||||
return http.StatusInternalServerError, err
|
||||
@ -257,11 +214,11 @@ func copyFiles(ctx context.Context, fs *FileSystem, src string, dst string, over
|
||||
if src == dst {
|
||||
return http.StatusMethodNotAllowed, errDestinationEqualsSource
|
||||
}
|
||||
srcAccount, srcPath, driver, err := ParsePath(src)
|
||||
srcAccount, srcPath, driver, err := common.ParsePath(src)
|
||||
if err != nil {
|
||||
return http.StatusMethodNotAllowed, err
|
||||
}
|
||||
dstAccount, dstPath, _, err := ParsePath(dst)
|
||||
dstAccount, dstPath, _, err := common.ParsePath(dst)
|
||||
if err != nil {
|
||||
return http.StatusMethodNotAllowed, err
|
||||
}
|
||||
@ -269,7 +226,7 @@ func copyFiles(ctx context.Context, fs *FileSystem, src string, dst string, over
|
||||
// TODO 跨账号复制
|
||||
return http.StatusMethodNotAllowed, errInvalidDestination
|
||||
}
|
||||
err = driver.Copy(srcPath, dstPath, srcAccount)
|
||||
err = operate.Copy(driver, srcAccount, srcPath, dstPath, true)
|
||||
if err != nil {
|
||||
return http.StatusInternalServerError, err
|
||||
}
|
||||
|
5
utils/json.go
Normal file
5
utils/json.go
Normal file
@ -0,0 +1,5 @@
|
||||
package utils
|
||||
|
||||
import jsoniter "github.com/json-iterator/go"
|
||||
|
||||
var Json = jsoniter.ConfigCompatibleWithStandardLibrary
|
Reference in New Issue
Block a user