Skip to content

Commit

Permalink
🐛 Fixes & enhancement for the download attachment effect
Browse files Browse the repository at this point in the history
  • Loading branch information
ItsTheSky committed Apr 29, 2024
1 parent 4cf456c commit d191f28
Showing 1 changed file with 13 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,19 @@ public void runEffect(@NotNull Event e) {
if (file.isDirectory())
file.mkdirs();

try (InputStream in = new URL(attachment.getUrl()).openStream()) {
Files.copy(in, file.isDirectory() ? Paths.get(file.getPath() + "/" + attachment.getFileName()) : Paths.get(file.getPath()));
} catch (IOException ex) {
if (!file.isDirectory()) {
File parent = file.getParentFile();
while (parent != null && !parent.exists()) {
parent.mkdirs();
parent = parent.getParentFile();
}
}

try {
attachment.getProxy().downloadToPath(
file.isDirectory() ? Paths.get(file.getPath() + "/" + attachment.getFileName()) : Paths.get(file.getPath())
);
} catch (Exception ex) {
DiSky.getErrorHandler().exception(e, ex);
}
restart();
Expand Down

0 comments on commit d191f28

Please sign in to comment.