Skip to content

Commit

Permalink
fix: only scan added files, not copied/moved
Browse files Browse the repository at this point in the history
However, ensure the data gets refreshed regardless, by hooking into the next
client side file list update after seeing a copy/move.
  • Loading branch information
foosel committed Sep 24, 2024
1 parent e81830b commit 7a5ad52
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
5 changes: 4 additions & 1 deletion octoprint_file_check/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,10 @@ def get_assets(self):
##~~ EventHandlerPlugin API

def on_event(self, event, payload):
if event == octoprint.events.Events.FILE_ADDED:
if (
event == octoprint.events.Events.FILE_ADDED
and payload.get("operation", "add") == "add"
):
self._executor.submit(
self._validate_file, payload["storage"], payload["path"], payload["type"]
)
Expand Down
15 changes: 15 additions & 0 deletions octoprint_file_check/static/js/file_check.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ $(function () {

self.issueNotification = undefined;

self.checkUpdateOnNextFileRefresh = false;

const ISSUES = {
travel_speed: {
title: gettext("Travel Speed Placeholder"),
Expand Down Expand Up @@ -233,6 +235,12 @@ $(function () {
}
};

self.onEventFileAdded = (payload) => {
if (payload.operation && payload.operation !== "add") {
self.checkUpdateOnNextFileRefresh = true;
}
};

self._handleNotification = function (data) {
let severity = "warning";

Expand Down Expand Up @@ -345,6 +353,13 @@ $(function () {
self.requestData();
}
);

self.filesViewModel.allItems.subscribe(() => {
if (self.checkUpdateOnNextFileRefresh) {
self.checkUpdateOnNextFileRefresh = false;
self.requestData();
}
});
};

self.onUserLoggedIn = self.onUserLoggedOut = function () {
Expand Down

0 comments on commit 7a5ad52

Please sign in to comment.