fixed Apikey
This commit is contained in:
parent
9bf5f6ae58
commit
d53b2665d5
@ -22,10 +22,14 @@ public class PublicDownload extends BaseHandler {
|
|||||||
String code = path.substring(lastSlash + 1);
|
String code = path.substring(lastSlash + 1);
|
||||||
String filename = path.substring(3, lastSlash);
|
String filename = path.substring(3, lastSlash);
|
||||||
|
|
||||||
|
if (tryHandleApiKey(ex, filename, code)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (code.matches(OTP_PATTERN)) {
|
if (code.matches(OTP_PATTERN)) {
|
||||||
handleOtp(ex, filename, code);
|
handleOtp(ex, filename, code);
|
||||||
} else {
|
} else {
|
||||||
handleApiKey(ex, filename, code);
|
writeError(ex, 404, "file not found");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -63,7 +67,7 @@ public class PublicDownload extends BaseHandler {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void handleApiKey(Exchange ex, String filename, String apiKey) throws Exception {
|
boolean tryHandleApiKey(Exchange ex, String filename, String apiKey) throws Exception {
|
||||||
String sql = "SELECT f.filename, f.mime_type, f.data FROM files f " +
|
String sql = "SELECT f.filename, f.mime_type, f.data FROM files f " +
|
||||||
"JOIN accounts a ON f.account_id = a.id " +
|
"JOIN accounts a ON f.account_id = a.id " +
|
||||||
"WHERE f.filename = ? AND a.api_key = ? LIMIT 1";
|
"WHERE f.filename = ? AND a.api_key = ? LIMIT 1";
|
||||||
@ -73,14 +77,14 @@ public class PublicDownload extends BaseHandler {
|
|||||||
ps.setString(2, apiKey);
|
ps.setString(2, apiKey);
|
||||||
try (ResultSet rs = ps.executeQuery()) {
|
try (ResultSet rs = ps.executeQuery()) {
|
||||||
if (!rs.next()) {
|
if (!rs.next()) {
|
||||||
writeError(ex, 404, "file not found");
|
return false;
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
String fname = rs.getString("filename");
|
String fname = rs.getString("filename");
|
||||||
String mimeType = rs.getString("mime_type");
|
String mimeType = rs.getString("mime_type");
|
||||||
byte[] data = rs.getBytes("data");
|
byte[] data = rs.getBytes("data");
|
||||||
ex.writeDownload(200, mimeType, fname,
|
ex.writeDownload(200, mimeType, fname,
|
||||||
new ByteArrayInputStream(data), data.length);
|
new ByteArrayInputStream(data), data.length);
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user