Fossil SCM

Finish(?) /uvlist file upload feature.

stephan 2024-06-24 17:22 uv-upload
Commit ecfdf535378408d9285316e614c3757d2f9f7e918270b145acec7f5923a0d912
--- src/style.uvlist.css
+++ src/style.uvlist.css
@@ -1,3 +1,7 @@
1
-body.uvlist form.uvupload label {
1
+body.uvlist input {
2
+ margin: 0.5em;
3
+}
4
+
5
+body.uvlist form {
26
display: block;
37
}
48
--- src/style.uvlist.css
+++ src/style.uvlist.css
@@ -1,3 +1,7 @@
1 body.uvlist form.uvupload label {
 
 
 
 
2 display: block;
3 }
4
--- src/style.uvlist.css
+++ src/style.uvlist.css
@@ -1,3 +1,7 @@
1 body.uvlist input {
2 margin: 0.5em;
3 }
4
5 body.uvlist form {
6 display: block;
7 }
8
--- src/unversioned.c
+++ src/unversioned.c
@@ -525,16 +525,48 @@
525525
526526
/*
527527
** Emit an HTML form for uploading a new unversioned file if
528528
** the current user has WrUnver permissions, else this is
529529
** a no-op.
530
+**
531
+** If this function detects that the form it emits has been submitted,
532
+** it will add the uploaded file to the unversioned file list before
533
+** returning.
534
+**
535
+** Intended only for use by /uvlist, and its form's action is that
536
+** page.
530537
*/
531
-static void uv_form_upload(void){
538
+static void uvlist_upload(void){
539
+ const char * aContent;
532540
if( !g.perm.WrUnver ) return;
533
- CX("<form class='uvupload' method='POST'>");
534
- CX("<label for='uvupload'>Select file to upload:</label>");
535
- CX("<input type='file' id='uvupload' name='uvupload'/>");
541
+ aContent = P("f");
542
+ if( aContent!=0 ){
543
+ const char * const zName = P("f:filename");
544
+ int const nContent = atoi(PD("f:bytes","0"));
545
+ const char * zError = 0;
546
+ Blob content;
547
+ if( zName[0]==0 ){
548
+ zError = "be an empty string";
549
+ }else if( contains_whitespace(zName) ){
550
+ zError = "contain spaces";
551
+ }
552
+ if( zError ){
553
+ fossil_fatal("Unversioned filenames may not %s: %Q",
554
+ zError, zName);
555
+ }
556
+ db_begin_transaction();
557
+ content_rcvid_init("#!fossil /uvlist upload");
558
+ blob_init(&content, aContent, nContent);
559
+ unversioned_write(zName, &content, time(0));
560
+ blob_reset(&content);
561
+ db_end_transaction(0);
562
+ CX("<div>Added: %s</div>", zName);
563
+ }
564
+ form_begin("enctype='multipart/form-data'", "%R/uvlist");
565
+ CX("<label for='uvupload'>Upload unversioned file:</label>");
566
+ CX("<input type='file' id='uvupload' name='f'/>");
567
+ CX("<input type='submit' value='Upload'/>");
536568
CX("</form>");
537569
}
538570
539571
/*
540572
** WEBPAGE: uvlist
@@ -558,13 +590,13 @@
558590
login_check_credentials();
559591
if( !g.perm.Read ){ login_needed(g.anon.Read); return; }
560592
cgi_check_for_malice();
561593
etag_check(ETAG_DATA,0);
562594
style_header("Unversioned Files");
595
+ uvlist_upload();
563596
if( !db_table_exists("repository","unversioned") ){
564597
@ No unversioned files on this server
565
- uv_form_upload();
566598
style_finish_page();
567599
return;
568600
}
569601
if( PB("byage") ) zOrderBy = "mtime DESC";
570602
if( PB("showdel") ) showDel = 1;
@@ -653,11 +685,10 @@
653685
@ </tfoot>
654686
@ </table></div>
655687
}else{
656688
@ No unversioned files on this server.
657689
}
658
- uv_form_upload();
659690
style_finish_page();
660691
}
661692
662693
/*
663694
** WEBPAGE: juvlist
664695
--- src/unversioned.c
+++ src/unversioned.c
@@ -525,16 +525,48 @@
525
526 /*
527 ** Emit an HTML form for uploading a new unversioned file if
528 ** the current user has WrUnver permissions, else this is
529 ** a no-op.
 
 
 
 
 
 
 
530 */
531 static void uv_form_upload(void){
 
532 if( !g.perm.WrUnver ) return;
533 CX("<form class='uvupload' method='POST'>");
534 CX("<label for='uvupload'>Select file to upload:</label>");
535 CX("<input type='file' id='uvupload' name='uvupload'/>");
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
536 CX("</form>");
537 }
538
539 /*
540 ** WEBPAGE: uvlist
@@ -558,13 +590,13 @@
558 login_check_credentials();
559 if( !g.perm.Read ){ login_needed(g.anon.Read); return; }
560 cgi_check_for_malice();
561 etag_check(ETAG_DATA,0);
562 style_header("Unversioned Files");
 
563 if( !db_table_exists("repository","unversioned") ){
564 @ No unversioned files on this server
565 uv_form_upload();
566 style_finish_page();
567 return;
568 }
569 if( PB("byage") ) zOrderBy = "mtime DESC";
570 if( PB("showdel") ) showDel = 1;
@@ -653,11 +685,10 @@
653 @ </tfoot>
654 @ </table></div>
655 }else{
656 @ No unversioned files on this server.
657 }
658 uv_form_upload();
659 style_finish_page();
660 }
661
662 /*
663 ** WEBPAGE: juvlist
664
--- src/unversioned.c
+++ src/unversioned.c
@@ -525,16 +525,48 @@
525
526 /*
527 ** Emit an HTML form for uploading a new unversioned file if
528 ** the current user has WrUnver permissions, else this is
529 ** a no-op.
530 **
531 ** If this function detects that the form it emits has been submitted,
532 ** it will add the uploaded file to the unversioned file list before
533 ** returning.
534 **
535 ** Intended only for use by /uvlist, and its form's action is that
536 ** page.
537 */
538 static void uvlist_upload(void){
539 const char * aContent;
540 if( !g.perm.WrUnver ) return;
541 aContent = P("f");
542 if( aContent!=0 ){
543 const char * const zName = P("f:filename");
544 int const nContent = atoi(PD("f:bytes","0"));
545 const char * zError = 0;
546 Blob content;
547 if( zName[0]==0 ){
548 zError = "be an empty string";
549 }else if( contains_whitespace(zName) ){
550 zError = "contain spaces";
551 }
552 if( zError ){
553 fossil_fatal("Unversioned filenames may not %s: %Q",
554 zError, zName);
555 }
556 db_begin_transaction();
557 content_rcvid_init("#!fossil /uvlist upload");
558 blob_init(&content, aContent, nContent);
559 unversioned_write(zName, &content, time(0));
560 blob_reset(&content);
561 db_end_transaction(0);
562 CX("<div>Added: %s</div>", zName);
563 }
564 form_begin("enctype='multipart/form-data'", "%R/uvlist");
565 CX("<label for='uvupload'>Upload unversioned file:</label>");
566 CX("<input type='file' id='uvupload' name='f'/>");
567 CX("<input type='submit' value='Upload'/>");
568 CX("</form>");
569 }
570
571 /*
572 ** WEBPAGE: uvlist
@@ -558,13 +590,13 @@
590 login_check_credentials();
591 if( !g.perm.Read ){ login_needed(g.anon.Read); return; }
592 cgi_check_for_malice();
593 etag_check(ETAG_DATA,0);
594 style_header("Unversioned Files");
595 uvlist_upload();
596 if( !db_table_exists("repository","unversioned") ){
597 @ No unversioned files on this server
 
598 style_finish_page();
599 return;
600 }
601 if( PB("byage") ) zOrderBy = "mtime DESC";
602 if( PB("showdel") ) showDel = 1;
@@ -653,11 +685,10 @@
685 @ </tfoot>
686 @ </table></div>
687 }else{
688 @ No unversioned files on this server.
689 }
 
690 style_finish_page();
691 }
692
693 /*
694 ** WEBPAGE: juvlist
695

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button