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 filename = path.substring(3, lastSlash);
|
||||
|
||||
if (tryHandleApiKey(ex, filename, code)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (code.matches(OTP_PATTERN)) {
|
||||
handleOtp(ex, filename, code);
|
||||
} 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 " +
|
||||
"JOIN accounts a ON f.account_id = a.id " +
|
||||
"WHERE f.filename = ? AND a.api_key = ? LIMIT 1";
|
||||
@ -73,14 +77,14 @@ public class PublicDownload extends BaseHandler {
|
||||
ps.setString(2, apiKey);
|
||||
try (ResultSet rs = ps.executeQuery()) {
|
||||
if (!rs.next()) {
|
||||
writeError(ex, 404, "file not found");
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
String fname = rs.getString("filename");
|
||||
String mimeType = rs.getString("mime_type");
|
||||
byte[] data = rs.getBytes("data");
|
||||
ex.writeDownload(200, mimeType, fname,
|
||||
new ByteArrayInputStream(data), data.length);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user