| | @@ -346,10 +346,11 @@ |
| 346 | 346 | void attach_commit( |
| 347 | 347 | const char *zName, /* The filename of the attachment */ |
| 348 | 348 | const char *zTarget, /* The artifact hash to attach to */ |
| 349 | 349 | const char *aContent, /* The content of the attachment */ |
| 350 | 350 | int szContent, /* The length of the attachment */ |
| 351 | + const char *zMimetype, /* Content mimetype or NULL */ |
| 351 | 352 | int needModerator, /* Moderate the attachment? */ |
| 352 | 353 | const char *zComment /* The comment for the attachment */ |
| 353 | 354 | ){ |
| 354 | 355 | Blob content; |
| 355 | 356 | Blob manifest; |
| | @@ -386,10 +387,13 @@ |
| 386 | 387 | if( n>0 ){ |
| 387 | 388 | blob_appendf(&manifest, "C %#F\n", n, zComment); |
| 388 | 389 | } |
| 389 | 390 | zDate = date_in_standard_format("now"); |
| 390 | 391 | blob_appendf(&manifest, "D %s\n", zDate); |
| 392 | + if( zMimetype && 0!=zMimetype[0] ){ |
| 393 | + blob_appendf(&manifest, "N %F\n", zMimetype); |
| 394 | + } |
| 391 | 395 | blob_appendf(&manifest, "U %F\n", login_name()); |
| 392 | 396 | md5sum_blob(&manifest, &cksum); |
| 393 | 397 | blob_appendf(&manifest, "Z %b\n", &cksum); |
| 394 | 398 | attach_put(&manifest, rid, needModerator); |
| 395 | 399 | assert( blob_is_reset(&manifest) ); |
| | @@ -414,10 +418,11 @@ |
| 414 | 418 | const char *zTechNote = P("technote"); |
| 415 | 419 | const char *zFrom = P("from"); |
| 416 | 420 | const char *aContent = P("f"); |
| 417 | 421 | const char *zName = PD("f:filename","unknown"); |
| 418 | 422 | const char *zComment = PD("comment", ""); |
| 423 | + const char *zMimetype = P("mimetype"); |
| 419 | 424 | const char *zTarget; |
| 420 | 425 | char * zTo = 0; |
| 421 | 426 | char *zTargetType = 0; |
| 422 | 427 | char *zExtraFree = 0; |
| 423 | 428 | int szContent = atoi(PD("f:bytes","0")); |
| | @@ -501,11 +506,12 @@ |
| 501 | 506 | /* Fall through and render form. */ |
| 502 | 507 | }else if( P("ok") && szContent>0 && (goodCaptcha = captcha_is_correct(0)) ){ |
| 503 | 508 | int needModerator = (zForumPost!=0 && forum_need_moderation()) || |
| 504 | 509 | (zTkt!=0 && ticket_need_moderation(0)) || |
| 505 | 510 | (zPage!=0 && wiki_need_moderation(0)); |
| 506 | | - attach_commit(zName, zTarget, aContent, szContent, needModerator, zComment); |
| 511 | + attach_commit(zName, zTarget, aContent, szContent, zMimetype, |
| 512 | + needModerator, zComment); |
| 507 | 513 | cgi_redirect(zTo ? zTo : zFrom); |
| 508 | 514 | } |
| 509 | 515 | |
| 510 | 516 | style_set_current_feature("attach"); |
| 511 | 517 | style_header("Add Attachment"); |
| | @@ -891,10 +897,12 @@ |
| 891 | 897 | ** is to be made. The attachment will be |
| 892 | 898 | ** to the most recently modified tech note |
| 893 | 899 | ** with the specified timestamp. |
| 894 | 900 | ** -t|--technote TECHNOTE-ID Specifies the technote to be |
| 895 | 901 | ** updated by its technote id |
| 902 | +** --mimetype TYPE Optional mimetype of the attached |
| 903 | +** content |
| 896 | 904 | ** |
| 897 | 905 | ** One of PAGENAME, DATETIME or TECHNOTE-ID must be specified. |
| 898 | 906 | ** |
| 899 | 907 | ** DATETIME may be "now" or "YYYY-MM-DDTHH:MM:SS.SSS". If in |
| 900 | 908 | ** year-month-day form, it may be truncated, the "T" may be replaced by |
| | @@ -915,16 +923,23 @@ |
| 915 | 923 | |
| 916 | 924 | if( strncmp(g.argv[2],"add",n)==0 ){ |
| 917 | 925 | const char *zPageName = 0; /* Name of the wiki page to attach to */ |
| 918 | 926 | const char *zFile; /* Name of the file to be attached */ |
| 919 | 927 | const char *zETime; /* The name of the technote to attach to */ |
| 928 | + const char *zMimetype; /* --mimetype NAME */ |
| 920 | 929 | Manifest *pWiki = 0; /* Parsed wiki page content */ |
| 921 | 930 | char *zBody = 0; /* Wiki page content */ |
| 922 | 931 | int rid; |
| 923 | 932 | const char *zTarget; /* Target of the attachment */ |
| 924 | 933 | Blob content; /* The content of the attachment */ |
| 934 | + zMimetype = find_option("mimetype",0,1); |
| 925 | 935 | zETime = find_option("technote","t",1); |
| 936 | + /* |
| 937 | + FIXME/TODO (2026-06-02): adapt this to use |
| 938 | + attachment_target_type() and, when attaching to tech notes and |
| 939 | + forum posts, always attach to their root version. |
| 940 | + */ |
| 926 | 941 | if( !zETime ){ |
| 927 | 942 | if( g.argc!=5 ){ |
| 928 | 943 | usage("add PAGENAME FILENAME"); |
| 929 | 944 | } |
| 930 | 945 | zPageName = g.argv[3]; |
| | @@ -967,10 +982,11 @@ |
| 967 | 982 | attach_commit( |
| 968 | 983 | zFile, /* The filename of the attachment */ |
| 969 | 984 | zTarget, /* The artifact hash to attach to */ |
| 970 | 985 | blob_buffer(&content), /* The content of the attachment */ |
| 971 | 986 | blob_size(&content), /* The length of the attachment */ |
| 987 | + zMimetype, /* Mimetype */ |
| 972 | 988 | 0, /* No need to moderate the attachment */ |
| 973 | 989 | "" /* Empty attachment comment */ |
| 974 | 990 | ); |
| 975 | 991 | if( !zETime ){ |
| 976 | 992 | fossil_print("Attached %s to wiki page %s.\n", zFile, zPageName); |
| 977 | 993 | |