commit | author | age
|
aed034
|
1 |
/* |
U |
2 |
neon-fm - Dateiverwaltung fuer neon |
|
3 |
Copyright (C) 2024 Ulrich Hilger |
|
4 |
|
|
5 |
This program is free software: you can redistribute it and/or modify |
|
6 |
it under the terms of the GNU Affero General Public License as |
|
7 |
published by the Free Software Foundation, either version 3 of the |
|
8 |
License, or (at your option) any later version. |
|
9 |
|
|
10 |
This program is distributed in the hope that it will be useful, |
|
11 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
13 |
GNU Affero General Public License for more details. |
|
14 |
|
|
15 |
You should have received a copy of the GNU Affero General Public License |
|
16 |
along with this program. If not, see <https://www.gnu.org/licenses/>. |
|
17 |
*/ |
|
18 |
package de.uhilger.neon.fm; |
|
19 |
|
|
20 |
import com.sun.net.httpserver.HttpContext; |
|
21 |
import com.sun.net.httpserver.HttpExchange; |
|
22 |
import de.uhilger.neon.FileServer; |
|
23 |
import de.uhilger.neon.HttpHelper; |
|
24 |
import de.uhilger.neon.HttpResponder; |
81b69f
|
25 |
import de.uhilger.fm.Catalog; |
aed034
|
26 |
import java.io.IOException; |
U |
27 |
|
|
28 |
/** |
|
29 |
* |
|
30 |
* @author Ulrich Hilger |
|
31 |
* @version 0.1, 05.11.2024 |
|
32 |
*/ |
|
33 |
public class FileList extends AbstractFileActor { |
|
34 |
|
|
35 |
public void run(HttpExchange exchange) { |
|
36 |
try { |
|
37 |
super.run(exchange); |
|
38 |
HttpContext ctx = exchange.getHttpContext(); |
|
39 |
String base = ctx.getAttributes().getOrDefault(FileServer.ATTR_FILE_BASE, "").toString(); |
|
40 |
if(base.length() == 0) { |
|
41 |
new HttpResponder().sendNotFound(exchange, exchange.getRequestURI().toString()); // not found |
|
42 |
} else { |
|
43 |
String fName = new HttpHelper().getFileName(exchange); |
|
44 |
if (fName.endsWith(FileServer.STR_SLASH)) { // Ordnerliste erzeugen |
81b69f
|
45 |
String json = new Catalog().list(fName, ctx.getPath(), base); |
aed034
|
46 |
if (null != json) { |
U |
47 |
new HttpResponder().antwortSenden(exchange, HttpResponder.SC_OK, json); |
|
48 |
} else { |
|
49 |
new HttpResponder().antwortSenden(exchange, HttpResponder.SC_OK, "{}"); // leere Liste |
|
50 |
} |
|
51 |
} else { |
|
52 |
new FileServer().serveFile(exchange); // Datei ausliefern |
|
53 |
} |
|
54 |
} |
|
55 |
} catch (IOException | IllegalArgumentException ex) { |
|
56 |
fehlerAntwort(exchange, ex); |
|
57 |
} finally { |
|
58 |
free(); |
|
59 |
} |
|
60 |
} |
|
61 |
} |