-
Notifications
You must be signed in to change notification settings - Fork 248
1177 enhancement apiv2 importfile fix todos #1874
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
5d39b58
Added more input validation in POST to the importfile helper
jessevz 576e316
Added automatic removing of outdated import files
jessevz 094ce7f
Merge branch 'dev' into 1177-enhancement-apiv2-importfile-fix-todos
22ffbf3
Fixed merge conflicts
1087aff
Fixed TUS path
ea876b9
Fixed warnings
108e7e5
Fixed git merge issues and made tus file locations configurable
6203afd
Fixed another merge mistake
e5c29b7
Improved cleaning of outdated uploaded files
3842122
Added checking for empty file for HEAD request for importfile
336d963
Fixed bug in cleaning
b2ec8d3
Improved expired file handling
f5c0d3d
Merge branch 'dev' into 1177-enhancement-apiv2-importfile-fix-todos
jessevz 947b2dd
Removed cron since that is not needed anymore
4fdb039
Merge remote-tracking branch 'refs/remotes/origin/1177-enhancement-ap…
5a3ba47
Resolved copilot review
c8b1c0a
Fixed path traversal prevention
5174312
Removed unnesesary actions from Dockerfile
e745582
Fixed copilot second review
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -621,55 +621,91 @@ public static function checkTaskWrapperCompleted($taskWrapper) { | |||||||||||||||||||||||
| } | ||||||||||||||||||||||||
| return true; | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| public static function cleaning() { | ||||||||||||||||||||||||
| $entry = Factory::getStoredValueFactory()->get(DCleaning::LAST_CLEANING); | ||||||||||||||||||||||||
| if ($entry == null) { | ||||||||||||||||||||||||
| $entry = new StoredValue(DCleaning::LAST_CLEANING, 0); | ||||||||||||||||||||||||
| Factory::getStoredValueFactory()->save($entry); | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
| $time = time(); | ||||||||||||||||||||||||
| if ($time - $entry->getVal() > 600) { | ||||||||||||||||||||||||
| self::agentStatCleaning(); | ||||||||||||||||||||||||
| self::zapCleaning(); | ||||||||||||||||||||||||
| self::tusFileCleaning(); | ||||||||||||||||||||||||
| Factory::getStoredValueFactory()->set($entry, StoredValue::VAL, $time); | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||
| * Checks if it is longer than 10 mins since the last time it was checked if there are | ||||||||||||||||||||||||
| * any old agent statistic entries which can be deleted. If necessary, check is executed | ||||||||||||||||||||||||
| * and old entries are deleted. | ||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||
| public static function agentStatCleaning() { | ||||||||||||||||||||||||
| $entry = Factory::getStoredValueFactory()->get(DStats::LAST_STAT_CLEANING); | ||||||||||||||||||||||||
| if ($entry == null) { | ||||||||||||||||||||||||
| $entry = new StoredValue(DStats::LAST_STAT_CLEANING, 0); | ||||||||||||||||||||||||
| Factory::getStoredValueFactory()->save($entry); | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
| if (time() - $entry->getVal() > 600) { | ||||||||||||||||||||||||
| $lifetime = intval(SConfig::getInstance()->getVal(DConfig::AGENT_DATA_LIFETIME)); | ||||||||||||||||||||||||
| if ($lifetime <= 0) { | ||||||||||||||||||||||||
| $lifetime = 3600; | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
| $qF = new QueryFilter(AgentStat::TIME, time() - $lifetime, "<="); | ||||||||||||||||||||||||
| Factory::getAgentStatFactory()->massDeletion([Factory::FILTER => $qF]); | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| $qF = new QueryFilter(Speed::TIME, time() - $lifetime, "<="); | ||||||||||||||||||||||||
| Factory::getSpeedFactory()->massDeletion([Factory::FILTER => $qF]); | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| Factory::getStoredValueFactory()->set($entry, StoredValue::VAL, time()); | ||||||||||||||||||||||||
| $lifetime = intval(SConfig::getInstance()->getVal(DConfig::AGENT_DATA_LIFETIME)); | ||||||||||||||||||||||||
| if ($lifetime <= 0) { | ||||||||||||||||||||||||
| $lifetime = 3600; | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
| $qF = new QueryFilter(AgentStat::TIME, time() - $lifetime, "<="); | ||||||||||||||||||||||||
| Factory::getAgentStatFactory()->massDeletion([Factory::FILTER => $qF]); | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| $qF = new QueryFilter(Speed::TIME, time() - $lifetime, "<="); | ||||||||||||||||||||||||
| Factory::getSpeedFactory()->massDeletion([Factory::FILTER => $qF]); | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||
| * Used by the solver. Cleans the zap-queue | ||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||
| public static function zapCleaning() { | ||||||||||||||||||||||||
| $entry = Factory::getStoredValueFactory()->get(DZaps::LAST_ZAP_CLEANING); | ||||||||||||||||||||||||
| if ($entry == null) { | ||||||||||||||||||||||||
| $entry = new StoredValue(DZaps::LAST_ZAP_CLEANING, 0); | ||||||||||||||||||||||||
| Factory::getStoredValueFactory()->save($entry); | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
| if (time() - $entry->getVal() > 600) { | ||||||||||||||||||||||||
| $zapFilter = new QueryFilter(Zap::SOLVE_TIME, time() - 600, "<="); | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| // delete dependencies on AgentZap | ||||||||||||||||||||||||
| $zaps = Factory::getZapFactory()->filter([Factory::FILTER => $zapFilter]); | ||||||||||||||||||||||||
| $zapIds = Util::arrayOfIds($zaps); | ||||||||||||||||||||||||
| $uS = new UpdateSet(AgentZap::LAST_ZAP_ID, null); | ||||||||||||||||||||||||
| $qF = new ContainFilter(AgentZap::LAST_ZAP_ID, $zapIds); | ||||||||||||||||||||||||
| Factory::getAgentZapFactory()->massUpdate([Factory::FILTER => $qF, Factory::UPDATE => $uS]); | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| Factory::getZapFactory()->massDeletion([Factory::FILTER => $zapFilter]); | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| Factory::getStoredValueFactory()->set($entry, StoredValue::VAL, time()); | ||||||||||||||||||||||||
| $zapFilter = new QueryFilter(Zap::SOLVE_TIME, time() - 600, "<="); | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| // delete dependencies on AgentZap | ||||||||||||||||||||||||
| $zaps = Factory::getZapFactory()->filter([Factory::FILTER => $zapFilter]); | ||||||||||||||||||||||||
| $zapIds = Util::arrayOfIds($zaps); | ||||||||||||||||||||||||
| $uS = new UpdateSet(AgentZap::LAST_ZAP_ID, null); | ||||||||||||||||||||||||
| $qF = new ContainFilter(AgentZap::LAST_ZAP_ID, $zapIds); | ||||||||||||||||||||||||
| Factory::getAgentZapFactory()->massUpdate([Factory::FILTER => $qF, Factory::UPDATE => $uS]); | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| Factory::getZapFactory()->massDeletion([Factory::FILTER => $zapFilter]); | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||
| * Cleans up stale TUS upload files. | ||||||||||||||||||||||||
| * | ||||||||||||||||||||||||
| * This method scans the TUS metadata directory for .meta files, reads their | ||||||||||||||||||||||||
| * metadata to determine upload expiration, and removes expired metadata files | ||||||||||||||||||||||||
| * together with their corresponding upload (.part) files. It performs file | ||||||||||||||||||||||||
| * system operations and may delete files on disk. | ||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||
| public static function tusFileCleaning() { | ||||||||||||||||||||||||
| $tusDirectory = Factory::getStoredValueFactory()->get(DDirectories::TUS)->getVal(); | ||||||||||||||||||||||||
| $uploadDirectory = $tusDirectory . DIRECTORY_SEPARATOR . "uploads" . DIRECTORY_SEPARATOR; | ||||||||||||||||||||||||
| $metaDirectory = $tusDirectory . DIRECTORY_SEPARATOR . "meta" . DIRECTORY_SEPARATOR; | ||||||||||||||||||||||||
| $expiration_time = time() + 3600; | ||||||||||||||||||||||||
| if (file_exists($metaDirectory) && is_dir($metaDirectory)) { | ||||||||||||||||||||||||
| if ($metaDirectoryHandler = opendir($metaDirectory)){ | ||||||||||||||||||||||||
| while ($file = readdir($metaDirectoryHandler)) { | ||||||||||||||||||||||||
jessevz marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||||||||
| if (str_ends_with($file, ".meta")) { | ||||||||||||||||||||||||
| $metaFile = $metaDirectory . $file; | ||||||||||||||||||||||||
| $metadata = (array)json_decode(file_get_contents($metaFile), true) ; | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
| $metadata = (array)json_decode(file_get_contents($metaFile), true) ; | |
| $metaContent = file_get_contents($metaFile); | |
| $metadata = json_decode($metaContent, true); | |
| if (!is_array($metadata) || json_last_error() !== JSON_ERROR_NONE) { | |
| // Invalid or unreadable metadata JSON, skip this file | |
| continue; | |
| } | |
| if (!isset($metadata['upload_expires']) || !is_numeric($metadata['upload_expires'])) { | |
| // Missing or invalid upload_expires field, skip this file | |
| continue; | |
| } |
jessevz marked this conversation as resolved.
Show resolved
Hide resolved
jessevz marked this conversation as resolved.
Show resolved
Hide resolved
jessevz marked this conversation as resolved.
Show resolved
Hide resolved
jessevz marked this conversation as resolved.
Show resolved
Hide resolved
jessevz marked this conversation as resolved.
Show resolved
Hide resolved
jessevz marked this conversation as resolved.
Show resolved
Hide resolved
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.