Skip to content

Commit 844fd4e

Browse files
committed
First commit
1 parent dbf8197 commit 844fd4e

33 files changed

+864
-0
lines changed

.gitignore

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,18 @@
2020

2121
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
2222
hs_err_pid*
23+
24+
.idea/workspace.xml
25+
.idea/**/gradle.xml
26+
.idea/**/libraries
27+
.idea/**/dataSources/
28+
.idea/**/dataSources.ids
29+
.idea/**/dataSources.xml
30+
.idea/**/dataSources.local.xml
31+
.idea/**/sqlDataSources.xml
32+
.idea/**/dynamic.xml
33+
.idea/**/uiDesigner.xml
34+
.idea/**/workspace.xml
35+
.idea/**/tasks.xml
36+
.idea/dictionaries
37+
.idea_modules/

.idea/artifacts/JDHttpApi_jar.xml

Lines changed: 14 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/compiler.xml

Lines changed: 18 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/libraries/Core.xml

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/misc.xml

Lines changed: 13 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/modules.xml

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/vcs.xml

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

JDHttpApi.iml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4">
3+
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_5">
4+
<output url="file://$MODULE_DIR$/target/classes" />
5+
<output-test url="file://$MODULE_DIR$/target/test-classes" />
6+
<content url="file://$MODULE_DIR$">
7+
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
8+
<sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" />
9+
<sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
10+
<excludeFolder url="file://$MODULE_DIR$/target" />
11+
</content>
12+
<orderEntry type="inheritedJdk" />
13+
<orderEntry type="sourceFolder" forTests="false" />
14+
<orderEntry type="library" name="Core" level="project" />
15+
<orderEntry type="library" name="Maven: org.eclipse.jetty:jetty-server:9.4.7.v20170914" level="project" />
16+
<orderEntry type="library" name="Maven: javax.servlet:javax.servlet-api:3.1.0" level="project" />
17+
<orderEntry type="library" name="Maven: org.eclipse.jetty:jetty-http:9.4.7.v20170914" level="project" />
18+
<orderEntry type="library" name="Maven: org.eclipse.jetty:jetty-util:9.4.7.v20170914" level="project" />
19+
<orderEntry type="library" name="Maven: org.eclipse.jetty:jetty-io:9.4.7.v20170914" level="project" />
20+
<orderEntry type="library" name="Maven: com.google.code.gson:gson:2.8.2" level="project" />
21+
</component>
22+
</module>

README.md

Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,127 @@
11
# JDHttpAPI
22
JDownloader2 plugin with a local HTTP API to add new files for download
3+
4+
This plugin is loaded by JDownloader2, which then starts up an embedded Jetty
5+
HTTP server to receive
6+
7+
From there, just about anything can send requests to queue up a new link. I
8+
like to use [Tampermonkey userscripts](https://tampermonkey.net/) to scrape
9+
links directly from web pages as I browse.
10+
11+
Note: it binds to your IP address, therefore other PCs on the network can add
12+
links. Configure a password or update the code to bind to something else -
13+
there is not currently a way configure local-only access. This plugin also
14+
accepts all Origins over ajax.
15+
16+
## Install
17+
18+
1. Close JDownloader.
19+
2. Build or download the `JDHttpApi.jar` file.
20+
3. Place that file in `./extensions/` inside the JDownloader2 program folder.
21+
3. Open the file `./tmp/extensioncache/extensionInfos.json` in your JD program
22+
folder and insert the following JSON as a new element in the array:
23+
24+
```
25+
{
26+
"settings" : true,
27+
"configInterface" : "org.jdownloader.extensions.httpAPI.HttpAPIConfig",
28+
"quickToggle" : false,
29+
"headlessRunnable" : true,
30+
"description" : "Http API.",
31+
"lng" : "en_US",
32+
"iconPath" : "folder_add",
33+
"linuxRunnable" : true,
34+
"macRunnable" : true,
35+
"name" : "HTTP API",
36+
"version" : -1,
37+
"windowsRunnable" : true,
38+
"classname" : "org.jdownloader.extensions.httpAPI.HttpAPIExtension",
39+
"jarPath" : "/absolute/path/to/jd2/extensions/JDHttpApi.jar"
40+
}
41+
```
42+
43+
4. Open the file `./update/versioninfo/JD/extensions.installed.json` inside the
44+
JD program folder and insert the string `"jdhttpapi"` as the last element
45+
in the JSON array.
46+
5. Start JDownloader2 and go to the settings page to enable the extension.
47+
48+
Note: there is no official extension install process, so most of this is
49+
tricking JD into thinking the JAR is already installed. It's possible that
50+
an update will trigger a cache invalidation that boots out this extension. Just
51+
reapply the steps above and you should get it back.
52+
53+
## Configure
54+
55+
This plugin has four settings to configure through the JDownloader GUI. In order
56+
to make changes take effect, disable and then re-enable the extension.
57+
58+
1. Use a password: require password authentication.
59+
2. Port: the port that the HTTP server listens on. Defaults to 8297.
60+
3. Password: If you've enabled the password feature, set it here.
61+
4. Allow Get: This disables HTTP GET access to the API. When enabled, you
62+
must POST new links as JSON. This can help you reduce exposure to CSRF
63+
vulnerabilities, especially when combined with a password.
64+
65+
## Use
66+
67+
There is currently only one URL: `/addLink`. You may submit via POST or GET.
68+
69+
### GET Service
70+
71+
There are three parameters, only `url` is required:
72+
73+
* `url`: The URL to add.
74+
* `packageName`: If you want to configure a custom package name, send it here.
75+
* `forcePackageName`: Set this to `true` to set the package name. For whatever
76+
reason, this is a separate field in JD's internals but if you don't force
77+
it, the package name will not be changed. It's possible I am hooking in too
78+
late in the process.
79+
80+
The response has three possible values:
81+
82+
On success: `{"success":true}`
83+
On malformed input: `{"errorMessage":"some error message"}`
84+
On authentication failure: `Login to access API` (this is not JSON)
85+
86+
CURL Examples:
87+
88+
```
89+
curl 'http://localhost:8297/addLink?url=https://i.imgur.com/muChjiN.jpg'
90+
curl 'http://localhost:8297/addLink?url=https://i.imgur.com/muChjiN.jpg&packageName=cutebunny&forcePackageName=true'
91+
```
92+
93+
### POST Service
94+
95+
Send a JSON object via POST with the same values as in the GET request:
96+
97+
```
98+
curl -X POST 'http://localhost:8297/addLink' \
99+
-d '{"url":"https://i.imgur.com/muChjiN.jpg"}'
100+
curl -X POST 'http://localhost:8297/addLink' \
101+
-d '{"url":"https://i.imgur.com/muChjiN.jpg","packageName":"cutebunny","forcePackageName":true}'
102+
```
103+
104+
### Authentication
105+
106+
If you choose to use a password, send it as the password portion of HTTP Basic
107+
Authentication - leave the username blank.
108+
109+
CURL Example:
110+
111+
```
112+
curl -u ':mypassword' 'http://192.168.1.7:8297/addLink?url=https://i.imgur.com/muChjiN.jpg'
113+
curl -u ':mypassword' -X POST 'http://localhost:8297/addLink' \
114+
-d '{"url":"https://i.imgur.com/muChjiN.jpg"}'
115+
```
116+
117+
## Errata
118+
119+
JDownloader2's extension system is surprisingly
120+
modular and easy to understand (aside from the install process). Feel free to
121+
use this project as an example for building other JD extensions as even the
122+
built-in ones are a bit more complex than this. Just make sure to have
123+
[the source code](https://svn.jdownloader.org/projects/jd) open up in
124+
another window for reference - there is virtually no documentation available
125+
and this project only uses the bare minimum of features.
126+
127+

lib/Core.jar

7.57 MB
Binary file not shown.

lib/JDGUI.jar

1.33 MB
Binary file not shown.

lib/JDownloader.jar

3.17 MB
Binary file not shown.

pom.xml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
7+
<groupId>jdownloaderPlugins</groupId>
8+
<artifactId>JDownloaderPlugins</artifactId>
9+
<version>1.0-SNAPSHOT</version>
10+
<dependencies>
11+
<!-- https://mvnrepository.com/artifact/org.eclipse.jetty/jetty-server -->
12+
<dependency>
13+
<groupId>org.eclipse.jetty</groupId>
14+
<artifactId>jetty-server</artifactId>
15+
<version>9.4.7.v20170914</version>
16+
</dependency>
17+
<dependency>
18+
    <groupId>com.google.code.gson</groupId>
19+
    <artifactId>gson</artifactId>
20+
    <version>2.8.2</version>
21+
</dependency>
22+
</dependencies>
23+
24+
</project>

settings-screenshot.png

10.4 KB
Loading

src/main/java/META-INF/MANIFEST.MF

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Manifest-Version: 1.0
2+
Class-Path: jetty-io-9.4.7.v20170914.jar jetty-server-9.4.7.v20170914.
3+
jar Core.jar JDownloader.jar JDGUI.jar gson-2.8.2.jar jetty-http-9.4.
4+
7.v20170914.jar javax.servlet-api-3.1.0.jar jetty-util-9.4.7.v2017091
5+
4.jar
6+
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package org.jdownloader.extensions.httpAPI;
2+
3+
import org.appwork.storage.config.handler.BooleanKeyHandler;
4+
import org.appwork.storage.config.handler.IntegerKeyHandler;
5+
import org.appwork.storage.config.handler.StorageHandler;
6+
import org.appwork.storage.config.handler.StringKeyHandler;
7+
import org.appwork.utils.Application;
8+
import org.appwork.storage.config.ConfigUtils;
9+
import org.appwork.storage.config.JsonConfig;
10+
11+
public class CFG_HTTPAPI {
12+
public static void main(String[] args) {
13+
ConfigUtils.printStaticMappings(HttpAPIConfig.class, "Application.getResource(\"cfg/\" + " + HttpAPIExtension.class.getSimpleName() + ".class.getName())");
14+
}
15+
16+
public static final HttpAPIConfig CFG = JsonConfig.create(Application.getResource("cfg/" + HttpAPIExtension.class.getName()), HttpAPIConfig.class);
17+
18+
public static final StorageHandler<HttpAPIConfig> SH = (StorageHandler<HttpAPIConfig>) CFG._getStorageHandler();
19+
20+
public static final BooleanKeyHandler ENABLED = SH.getKeyHandler("Enabled", BooleanKeyHandler.class);
21+
22+
public static final IntegerKeyHandler PORT = SH.getKeyHandler("Port", IntegerKeyHandler.class);
23+
24+
public static final BooleanKeyHandler ALLOW_GET = SH.getKeyHandler("AllowGet", BooleanKeyHandler.class);
25+
26+
public static final BooleanKeyHandler USE_PASSWORD = SH.getKeyHandler("UsePassword", BooleanKeyHandler.class);
27+
28+
public static final StringKeyHandler PASSWORD = SH.getKeyHandler("Password", StringKeyHandler.class);
29+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package org.jdownloader.extensions.httpAPI;
2+
3+
import jd.plugins.ExtensionConfigInterface;
4+
import org.appwork.storage.config.annotations.AboutConfig;
5+
import org.appwork.storage.config.annotations.DefaultBooleanValue;
6+
import org.appwork.storage.config.annotations.DefaultIntValue;
7+
8+
public interface HttpAPIConfig extends ExtensionConfigInterface {
9+
10+
@AboutConfig
11+
@DefaultIntValue(8297)
12+
int getPort();
13+
void setPort(int port);
14+
15+
@AboutConfig
16+
@DefaultBooleanValue(false)
17+
boolean getAllowGet();
18+
void setAllowGet(boolean enabled);
19+
20+
@AboutConfig
21+
@DefaultBooleanValue(false)
22+
boolean getUsePassword();
23+
void setUsePassword(boolean enabled);
24+
25+
@AboutConfig
26+
String getPassword();
27+
void setPassword(String password);
28+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package org.jdownloader.extensions.httpAPI;
2+
3+
4+
import org.jdownloader.extensions.ExtensionConfigPanel;
5+
6+
import jd.gui.swing.jdgui.views.settings.panels.advanced.AdvancedConfigTableModel;
7+
import jd.gui.swing.jdgui.views.settings.panels.advanced.AdvancedTable;
8+
9+
public class HttpAPIConfigPanel extends ExtensionConfigPanel<HttpAPIExtension> {
10+
11+
private AdvancedConfigTableModel model;
12+
13+
public HttpAPIConfigPanel(HttpAPIExtension extension){
14+
super(extension);
15+
16+
add(new AdvancedTable(model= new AdvancedConfigTableModel("HttpAPIConfigPanel"){
17+
@Override
18+
public void refresh(String filterText){ _fireTableStructureChanged(register(), true);}
19+
}));
20+
model.refresh("HttpAPIConfigPanel");
21+
}
22+
23+
@Override
24+
public void save() {
25+
}
26+
27+
@Override
28+
public void updateContents() {
29+
30+
}
31+
}

0 commit comments

Comments
 (0)