Skip to content

Commit 33250e2

Browse files
FIX: file / folder deletion was not refreshed correctly
ADD: jobs now available in REST API Refactor code
1 parent d0cd4a7 commit 33250e2

File tree

7 files changed

+423
-143
lines changed

7 files changed

+423
-143
lines changed

src/rest.md

Lines changed: 71 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,76 @@ GET /API/view/list?view=right
113113
}
114114
```
115115

116+
## POST /API/jobs
117+
118+
Creates a new job to copy, move, or delete files/folders.
119+
120+
### Request
121+
122+
**Method:** POST
123+
**Path:** `/API/jobs`
124+
**Content-Type:** `application/json`
125+
126+
### Request Schema
127+
128+
| Field | Type | Required | Description |
129+
|-------|------|----------|-------------|
130+
| `operation` | string | Yes | Type of operation: "copy", "move", "delete" or "delete_empty_subfolders" |
131+
| `source` | string | Yes | Source file or directory path |
132+
| `target` | string | Conditional | Target directory path (required for "copy" and "move", ignored for "delete" or "delete_empty_subfolders") |
133+
134+
### Example Requests
135+
136+
**Copy operation:**
137+
```json
138+
{
139+
"operation": "copy",
140+
"source": "C:\\Users\\john\\Documents\\file.txt",
141+
"target": "C:\\Users\\john\\Backup"
142+
}
143+
```
144+
145+
**Move operation:**
146+
```json
147+
{
148+
"operation": "move",
149+
"source": "C:\\Users\\john\\Documents\\folder",
150+
"target": "C:\\Users\\john\\Archive"
151+
}
152+
```
153+
154+
**Delete operation:**
155+
```json
156+
{
157+
"operation": "delete",
158+
"source": "C:\\Users\\john\\Documents\\temp.txt"
159+
}
160+
```
161+
162+
### Response
163+
164+
**HTTP Status Codes:**
165+
- `201 Created` - Job successfully created and queued
166+
- `400 Bad Request` - Invalid operation type or missing required fields
167+
- `404 Not Found` - Source file/directory does not exist
168+
- `422 Unprocessable Entity` - Invalid paths or target directory does not exist
169+
170+
**Content-Type:** `application/json`
171+
172+
### Response Schema
173+
174+
| Field | Type | Description |
175+
|-------|------|-------------|
176+
| `status` | string | Current job status ("queued") |
177+
178+
### Example Response
179+
180+
```json
181+
{
182+
"status": "queued"
183+
}
184+
```
185+
116186
## POST /API/zombie/setdir
117187

118188
Sets the directory path for either the left or right view.
@@ -139,7 +209,7 @@ Sets the directory path for either the left or right view.
139209
}
140210
```
141211

142-
### Example Response
212+
### Response
143213

144214
**HTTP Status Codes:**
145215
- `204 No Content` - Directory successfully set

src/unit1.pas

Lines changed: 32 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@
103103
(* ADD: exclude in sync *)
104104
(* FIX: preserve selection and focus when reloading dir *)
105105
(* ADD: REST Server *)
106+
(* FIX: did not refresh folder if subfolder was deleted *)
106107
(* *)
107108
(******************************************************************************)
108109
(* Silk icon set 1.3 used *)
@@ -293,12 +294,12 @@
293294
Procedure DeleteShortcut;
294295
Procedure IncGetElementCounter(Const aFolder: String); // aFolder ohne Pathdelim am ende !
295296
Procedure DecGetElementCounter(Const aFolder: String); // aFolder ohne Pathdelim am ende !
297+
Procedure HandleJobQueue(); // Übernimmt alle Jobs die via AddToJobQueue eingetragen wurden ;)
296298
public
297299
fWorkThread: TWorkThread; // Bäh wieder Private machen !
298300
fLeftView, fRightView: TView; // Bäh wieder Private machen !
299301
Procedure LoadDir(Dir: String; Var View: TView; ForceElementBufferRefresh: Boolean = false);
300-
Procedure AddToJobQueue(Const Job: TJob); //Fügt non LCL Blocking in die JobQueue ein, zum Übernehmen muss HandleJobQueue aufgerufen werden !
301-
Procedure HandleJobQueue(); // Arbeitet die JobQueue ab und übergibt die Jobs an die Threads
302+
Procedure AddToJobQueue(Const Job: TJob); //Fügt non LCL Blocking in die JobQueue ein
302303
End;
303304

304305
Var
@@ -639,17 +640,20 @@
639640
End;
640641

641642
Procedure TForm1.FormClose(Sender: TObject; Var CloseAction: TCloseAction);
643+
Var
644+
Workthread_reference: TWorkThread;
642645
Begin
643646
FreeRestAPI;
644-
645-
If fWorkThread.JobsPending Then Begin
646-
fWorkThread.OnFinishJob := Nil; // Der User Braucht auch nicht mehr sehen dass wir die Löschen
647-
fWorkThread.CancelAllJobs();
648-
While fWorkThread.JobsPending Do Begin
647+
Workthread_reference := fWorkThread;
648+
fWorkThread := Nil; // Das sorgt dafür, dass der On Idle Handler nichts mehr macht ;)
649+
If Workthread_reference.JobsPending Then Begin
650+
Workthread_reference.OnFinishJob := Nil; // Der User Braucht auch nicht mehr sehen dass wir die Löschen
651+
Workthread_reference.CancelAllJobs();
652+
While Workthread_reference.JobsPending Do Begin
649653
sleep(1);
650654
End;
651655
End;
652-
fWorkThread.Terminate;
656+
Workthread_reference.Terminate;
653657
(*
654658
* theoretisch Idled der Thread im 1ms takt, d.h. nach 10ms ist er auf jeden Fall weg.
655659
*)
@@ -659,8 +663,8 @@
659663
fJobFifo.free;
660664
fJobFifo := Nil;
661665
Sleep(10);
662-
fWorkThread.free;
663-
fWorkThread := Nil;
666+
Workthread_reference.free;
667+
Workthread_reference := Nil;
664668

665669
finiFile.WriteString(iniLeft, iniLastDir, cbDirLeft.text);
666670
finiFile.WriteString(iniRight, iniLastDir, cbDirRight.text);
@@ -700,7 +704,6 @@
700704
j := fWorkThread.PopQuestion();
701705
j.Answer := fWorkThread.AllResult;
702706
AddToJobQueue(j);
703-
HandleJobQueue();
704707
End
705708
Else Begin
706709
form5.ModalResult := mrNone;
@@ -719,7 +722,6 @@
719722
j.ToAll := true;
720723
j.Answer := jaSkip;
721724
AddToJobQueue(j);
722-
HandleJobQueue();
723725
End
724726
Else Begin
725727
j.free;
@@ -730,11 +732,11 @@
730732
j.ToAll := Form5.CheckBox1.Checked;
731733
j.Answer := jaReplace;
732734
AddToJobQueue(j);
733-
HandleJobQueue();
734735
End;
735736
End;
736737
End;
737738
End;
739+
HandleJobQueue();
738740
End;
739741
sleep(1);
740742
End;
@@ -928,7 +930,6 @@
928930
End;
929931
AddToJobQueue(job);
930932
End;
931-
HandleJobQueue();
932933
End;
933934
End;
934935

@@ -1057,6 +1058,10 @@
10571058
oListview.SetFocus;
10581059
If assigned(oListview.ItemFocused) Then Begin
10591060
oListview.ItemFocused.Selected := true;
1061+
End
1062+
Else Begin
1063+
// Wir wählen eins in der "Nähe" aus, oder wenn der Itemindex auch kaputt ist, eben das 1.
1064+
ListViewSelectItemIndex(oListview, max(0, min(oListview.ItemIndex, oListview.Items.Count - 1)));
10601065
End;
10611066
key := 0;
10621067
exit;
@@ -1222,7 +1227,6 @@
12221227
AddtoCreateAndAddJobQueue(aListview.Items[i], jsCopy, aView^.aDirectory, oView^.aDirectory);
12231228
End;
12241229
End;
1225-
HandleJobQueue();
12261230
{$IFDEF Windows}
12271231
End;
12281232
{$ENDIF}
@@ -1237,7 +1241,6 @@
12371241
AddtoCreateAndAddJobQueue(aListview.Items[i], jsCopy, aView^.aDirectory, oView^.aDirectory);
12381242
End;
12391243
End;
1240-
HandleJobQueue();
12411244
End;
12421245
// F6 = Move
12431246
If key = VK_F6 Then Begin
@@ -1248,7 +1251,6 @@
12481251
AddtoCreateAndAddJobQueue(aListview.Items[i], jsMove, aView^.aDirectory, oView^.aDirectory);
12491252
End;
12501253
End;
1251-
HandleJobQueue();
12521254
End;
12531255
// F8 = Delete
12541256
If key = VK_F8 Then Begin
@@ -1259,7 +1261,6 @@
12591261
AddtoCreateAndAddJobQueue(aListview.Items[i], jsDel, aView^.aDirectory, '');
12601262
End;
12611263
End;
1262-
HandleJobQueue();
12631264
End;
12641265
// User Search eingaben ;)
12651266
If key = VK_ESCAPE Then Begin
@@ -1657,7 +1658,7 @@
16571658
While Not fJobFifo.isempty Do Begin
16581659
job := fJobFifo.Pop;
16591660
// Gibt es diesen Job schon in unseren Listen ?
1660-
If fWorkThread.ExistJob(job) Then Begin
1661+
If assigned(fWorkThread) And fWorkThread.ExistJob(job) Then Begin
16611662
If ID_NO = Application.MessageBox(pchar('Warning, Job:' + LineEnding + JobToString(job) + LineEnding + 'already exists in queue. Do you want to add the job anyway?')
16621663
, 'Warning'
16631664
, MB_YESNO Or MB_ICONQUESTION) Then Begin
@@ -1670,7 +1671,12 @@
16701671
n.Data := job;
16711672
form2.Invalidate;
16721673
// Aufnehmen in die Arbeiter Klasse ;)
1673-
fWorkThread.AddJob(job);
1674+
If assigned(fWorkThread) Then Begin
1675+
fWorkThread.AddJob(job);
1676+
End
1677+
Else Begin
1678+
job.free;
1679+
End;
16741680
End;
16751681
End;
16761682

@@ -1726,7 +1732,12 @@
17261732
End;
17271733
End;
17281734
jtDelFile, jtDelDir: Begin
1729-
s := IncludeTrailingPathDelimiter(ExtractFilePath(job.Source));
1735+
If Job.JobType = jtDelDir Then Begin
1736+
s := IncludeTrailingPathDelimiter(ExtractFilePath(ExcludeTrailingPathDelimiter(job.Source)));
1737+
End
1738+
Else Begin
1739+
s := IncludeTrailingPathDelimiter(ExtractFilePath(job.Source));
1740+
End;
17301741
decGetElementCounter(ExcludeTrailingPathDelimiter(s));
17311742
If s = fLeftView.aDirectory Then LoadDir(s, fLeftView);
17321743
If s = fRightView.aDirectory Then LoadDir(s, fRightView);

src/unit3.pas

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,6 @@
238238
form1.AddToJobQueue(job);
239239
End;
240240
End;
241-
Form1.HandleJobQueue();
242241
close;
243242
End;
244243

src/unit4.pas

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,6 @@
7474
If listbox1.ItemIndex <> -1 Then Begin
7575
form1.AddToJobQueue(TJob(ListBox1.Items.Objects[listbox1.ItemIndex]));
7676
ListBox1.Items.Delete(listbox1.ItemIndex);
77-
Form1.HandleJobQueue();
7877
End;
7978
End;
8079

src/unit6.pas

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,6 @@
253253
j.JobType := jtDelEmptyFolders;
254254
form1.AddToJobQueue(j);
255255
End;
256-
Form1.HandleJobQueue();
257256
ModalResult := mrOK;
258257
End;
259258

0 commit comments

Comments
 (0)