1
0
mirror of https://github.com/sasjs/core.git synced 2026-01-05 08:30:06 +00:00

feat: adding MARKDOWN support to mp_streamfile(), correcting Content-type case issue also

This commit is contained in:
Allan Bowe
2022-04-30 15:53:59 +00:00
parent 9e12409389
commit 61556b2de8
2 changed files with 60 additions and 42 deletions

51
all.sas
View File

@@ -11722,8 +11722,10 @@ create table &outds as
%mend mp_stprequests;/** %mend mp_stprequests;/**
@file @file
@brief Streams a file to _webout according to content type @brief Streams a file to _webout according to content type
@details Will set headers using appropriate functions (SAS 9 vs Viya) and send @details Will set headers using appropriate functions per the server type
content as a binary stream. (Viya, EBI, SASjs Server) and content as a binary stream.
A co
Usage: Usage:
@@ -11733,7 +11735,14 @@ create table &outds as
%mp_streamfile(contenttype=csv,inloc=/some/where.txt,outname=myfile.txt) %mp_streamfile(contenttype=csv,inloc=/some/where.txt,outname=myfile.txt)
@param [in] contenttype= (TEXT) Either TEXT, ZIP, CSV, EXCEL @param [in] contenttype= (TEXT) Supported:
@li CSV
@li EXCEL
@li MARKDOWN
@li TEXT
@li ZIP
Feel free to submit PRs to support more mime types! The official list is
here: https://www.iana.org/assignments/media-types/media-types.xhtml
@param [in] inloc= /path/to/file.ext to be sent @param [in] inloc= /path/to/file.ext to be sent
@param [in] inref= fileref of file to be sent (if provided, overrides `inloc`) @param [in] inref= fileref of file to be sent (if provided, overrides `inloc`)
@param [in] iftrue= (1=1) Provide a condition under which to execute. @param [in] iftrue= (1=1) Provide a condition under which to execute.
@@ -11779,7 +11788,7 @@ run;
%if &contentype=CSV %then %do; %if &contentype=CSV %then %do;
%if (&platform=SASMETA and &streamweb=1) %then %do; %if (&platform=SASMETA and &streamweb=1) %then %do;
data _null_; data _null_;
rc=stpsrv_header('Content-type','application/csv'); rc=stpsrv_header('Content-Type','application/csv');
rc=stpsrv_header('Content-disposition',"attachment; filename=&outname"); rc=stpsrv_header('Content-disposition',"attachment; filename=&outname");
run; run;
%end; %end;
@@ -11789,7 +11798,7 @@ run;
contentdisp="attachment; filename=&outname"; contentdisp="attachment; filename=&outname";
%end; %end;
%else %if &platform=SASJS %then %do; %else %if &platform=SASJS %then %do;
%mfs_httpheader(Content-type,application/csv) %mfs_httpheader(Content-Type,application/csv)
%mfs_httpheader(Content-disposition,%str(attachment; filename=&outname)) %mfs_httpheader(Content-disposition,%str(attachment; filename=&outname))
%end; %end;
%end; %end;
@@ -11797,7 +11806,7 @@ run;
/* suitable for XLS format */ /* suitable for XLS format */
%if (&platform=SASMETA and &streamweb=1) %then %do; %if (&platform=SASMETA and &streamweb=1) %then %do;
data _null_; data _null_;
rc=stpsrv_header('Content-type','application/vnd.ms-excel'); rc=stpsrv_header('Content-Type','application/vnd.ms-excel');
rc=stpsrv_header('Content-disposition',"attachment; filename=&outname"); rc=stpsrv_header('Content-disposition',"attachment; filename=&outname");
run; run;
%end; %end;
@@ -11807,14 +11816,14 @@ run;
contentdisp="attachment; filename=&outname"; contentdisp="attachment; filename=&outname";
%end; %end;
%else %if &platform=SASJS %then %do; %else %if &platform=SASJS %then %do;
%mfs_httpheader(Content-type,application/vnd.ms-excel) %mfs_httpheader(Content-Type,application/vnd.ms-excel)
%mfs_httpheader(Content-disposition,%str(attachment; filename=&outname)) %mfs_httpheader(Content-disposition,%str(attachment; filename=&outname))
%end; %end;
%end; %end;
%else %if &contentype=GIF or &contentype=JPEG or &contentype=PNG %then %do; %else %if &contentype=GIF or &contentype=JPEG or &contentype=PNG %then %do;
%if (&platform=SASMETA and &streamweb=1) %then %do; %if (&platform=SASMETA and &streamweb=1) %then %do;
data _null_; data _null_;
rc=stpsrv_header('Content-type',"image/%lowcase(&contenttype)"); rc=stpsrv_header('Content-Type',"image/%lowcase(&contenttype)");
run; run;
%end; %end;
%else %if &platform=SASVIYA %then %do; %else %if &platform=SASVIYA %then %do;
@@ -11822,30 +11831,30 @@ run;
contenttype="image/%lowcase(&contenttype)"; contenttype="image/%lowcase(&contenttype)";
%end; %end;
%else %if &platform=SASJS %then %do; %else %if &platform=SASJS %then %do;
%mfs_httpheader(Content-type,image/%lowcase(&contenttype)) %mfs_httpheader(Content-Type,image/%lowcase(&contenttype))
%end; %end;
%end; %end;
%else %if &contentype=HTML %then %do; %else %if &contentype=HTML or &contenttype=MARKDOWN %then %do;
%if (&platform=SASMETA and &streamweb=1) %then %do; %if (&platform=SASMETA and &streamweb=1) %then %do;
data _null_; data _null_;
rc=stpsrv_header('Content-type','text/html'); rc=stpsrv_header('Content-Type',"text/%lowcase(&contenttype)");
rc=stpsrv_header('Content-disposition',"attachment; filename=&outname"); rc=stpsrv_header('Content-disposition',"attachment; filename=&outname");
run; run;
%end; %end;
%else %if &platform=SASVIYA %then %do; %else %if &platform=SASVIYA %then %do;
filename &outref filesrvc parenturi="&SYS_JES_JOB_URI" name="_webout.json" filename &outref filesrvc parenturi="&SYS_JES_JOB_URI" name="_webout.json"
contenttype="text/html" contenttype="text/%lowcase(&contenttype)"
contentdisp="attachment; filename=&outname"; contentdisp="attachment; filename=&outname";
%end; %end;
%else %if &platform=SASJS %then %do; %else %if &platform=SASJS %then %do;
%mfs_httpheader(Content-type,text/html) %mfs_httpheader(Content-Type,text/%lowcase(&contenttype))
%mfs_httpheader(Content-disposition,%str(attachment; filename=&outname)) %mfs_httpheader(Content-disposition,%str(attachment; filename=&outname))
%end; %end;
%end; %end;
%else %if &contentype=TEXT %then %do; %else %if &contentype=TEXT %then %do;
%if (&platform=SASMETA and &streamweb=1) %then %do; %if (&platform=SASMETA and &streamweb=1) %then %do;
data _null_; data _null_;
rc=stpsrv_header('Content-type','application/text'); rc=stpsrv_header('Content-Type','application/text');
rc=stpsrv_header('Content-disposition',"attachment; filename=&outname"); rc=stpsrv_header('Content-disposition',"attachment; filename=&outname");
run; run;
%end; %end;
@@ -11855,14 +11864,14 @@ run;
contentdisp="attachment; filename=&outname"; contentdisp="attachment; filename=&outname";
%end; %end;
%else %if &platform=SASJS %then %do; %else %if &platform=SASJS %then %do;
%mfs_httpheader(Content-type,application/text) %mfs_httpheader(Content-Type,application/text)
%mfs_httpheader(Content-disposition,%str(attachment; filename=&outname)) %mfs_httpheader(Content-disposition,%str(attachment; filename=&outname))
%end; %end;
%end; %end;
%else %if &contentype=WOFF or &contentype=WOFF2 or &contentype=TTF %then %do; %else %if &contentype=WOFF or &contentype=WOFF2 or &contentype=TTF %then %do;
%if (&platform=SASMETA and &streamweb=1) %then %do; %if (&platform=SASMETA and &streamweb=1) %then %do;
data _null_; data _null_;
rc=stpsrv_header('Content-type',"font/%lowcase(&contenttype)"); rc=stpsrv_header('Content-Type',"font/%lowcase(&contenttype)");
run; run;
%end; %end;
%else %if &platform=SASVIYA %then %do; %else %if &platform=SASVIYA %then %do;
@@ -11870,13 +11879,13 @@ run;
contenttype="font/%lowcase(&contenttype)"; contenttype="font/%lowcase(&contenttype)";
%end; %end;
%else %if &platform=SASJS %then %do; %else %if &platform=SASJS %then %do;
%mfs_httpheader(Content-type,font/%lowcase(&contenttype)) %mfs_httpheader(Content-Type,font/%lowcase(&contenttype))
%end; %end;
%end; %end;
%else %if &contentype=XLSX %then %do; %else %if &contentype=XLSX %then %do;
%if (&platform=SASMETA and &streamweb=1) %then %do; %if (&platform=SASMETA and &streamweb=1) %then %do;
data _null_; data _null_;
rc=stpsrv_header('Content-type', rc=stpsrv_header('Content-Type',
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'); 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
rc=stpsrv_header('Content-disposition',"attachment; filename=&outname"); rc=stpsrv_header('Content-disposition',"attachment; filename=&outname");
run; run;
@@ -11888,7 +11897,7 @@ run;
contentdisp="attachment; filename=&outname"; contentdisp="attachment; filename=&outname";
%end; %end;
%else %if &platform=SASJS %then %do; %else %if &platform=SASJS %then %do;
%mfs_httpheader(Content-type %mfs_httpheader(Content-Type
,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet ,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
) )
%mfs_httpheader(Content-disposition,%str(attachment; filename=&outname)) %mfs_httpheader(Content-disposition,%str(attachment; filename=&outname))
@@ -11897,7 +11906,7 @@ run;
%else %if &contentype=ZIP %then %do; %else %if &contentype=ZIP %then %do;
%if (&platform=SASMETA and &streamweb=1) %then %do; %if (&platform=SASMETA and &streamweb=1) %then %do;
data _null_; data _null_;
rc=stpsrv_header('Content-type','application/zip'); rc=stpsrv_header('Content-Type','application/zip');
rc=stpsrv_header('Content-disposition',"attachment; filename=&outname"); rc=stpsrv_header('Content-disposition',"attachment; filename=&outname");
run; run;
%end; %end;
@@ -11907,7 +11916,7 @@ run;
contentdisp="attachment; filename=&outname"; contentdisp="attachment; filename=&outname";
%end; %end;
%else %if &platform=SASJS %then %do; %else %if &platform=SASJS %then %do;
%mfs_httpheader(Content-type,application/zip) %mfs_httpheader(Content-Type,application/zip)
%mfs_httpheader(Content-disposition,%str(attachment; filename=&outname)) %mfs_httpheader(Content-disposition,%str(attachment; filename=&outname))
%end; %end;
%end; %end;

View File

@@ -1,8 +1,10 @@
/** /**
@file @file
@brief Streams a file to _webout according to content type @brief Streams a file to _webout according to content type
@details Will set headers using appropriate functions (SAS 9 vs Viya) and send @details Will set headers using appropriate functions per the server type
content as a binary stream. (Viya, EBI, SASjs Server) and content as a binary stream.
A co
Usage: Usage:
@@ -12,7 +14,14 @@
%mp_streamfile(contenttype=csv,inloc=/some/where.txt,outname=myfile.txt) %mp_streamfile(contenttype=csv,inloc=/some/where.txt,outname=myfile.txt)
@param [in] contenttype= (TEXT) Either TEXT, ZIP, CSV, EXCEL @param [in] contenttype= (TEXT) Supported:
@li CSV
@li EXCEL
@li MARKDOWN
@li TEXT
@li ZIP
Feel free to submit PRs to support more mime types! The official list is
here: https://www.iana.org/assignments/media-types/media-types.xhtml
@param [in] inloc= /path/to/file.ext to be sent @param [in] inloc= /path/to/file.ext to be sent
@param [in] inref= fileref of file to be sent (if provided, overrides `inloc`) @param [in] inref= fileref of file to be sent (if provided, overrides `inloc`)
@param [in] iftrue= (1=1) Provide a condition under which to execute. @param [in] iftrue= (1=1) Provide a condition under which to execute.
@@ -58,7 +67,7 @@ run;
%if &contentype=CSV %then %do; %if &contentype=CSV %then %do;
%if (&platform=SASMETA and &streamweb=1) %then %do; %if (&platform=SASMETA and &streamweb=1) %then %do;
data _null_; data _null_;
rc=stpsrv_header('Content-type','application/csv'); rc=stpsrv_header('Content-Type','application/csv');
rc=stpsrv_header('Content-disposition',"attachment; filename=&outname"); rc=stpsrv_header('Content-disposition',"attachment; filename=&outname");
run; run;
%end; %end;
@@ -68,7 +77,7 @@ run;
contentdisp="attachment; filename=&outname"; contentdisp="attachment; filename=&outname";
%end; %end;
%else %if &platform=SASJS %then %do; %else %if &platform=SASJS %then %do;
%mfs_httpheader(Content-type,application/csv) %mfs_httpheader(Content-Type,application/csv)
%mfs_httpheader(Content-disposition,%str(attachment; filename=&outname)) %mfs_httpheader(Content-disposition,%str(attachment; filename=&outname))
%end; %end;
%end; %end;
@@ -76,7 +85,7 @@ run;
/* suitable for XLS format */ /* suitable for XLS format */
%if (&platform=SASMETA and &streamweb=1) %then %do; %if (&platform=SASMETA and &streamweb=1) %then %do;
data _null_; data _null_;
rc=stpsrv_header('Content-type','application/vnd.ms-excel'); rc=stpsrv_header('Content-Type','application/vnd.ms-excel');
rc=stpsrv_header('Content-disposition',"attachment; filename=&outname"); rc=stpsrv_header('Content-disposition',"attachment; filename=&outname");
run; run;
%end; %end;
@@ -86,14 +95,14 @@ run;
contentdisp="attachment; filename=&outname"; contentdisp="attachment; filename=&outname";
%end; %end;
%else %if &platform=SASJS %then %do; %else %if &platform=SASJS %then %do;
%mfs_httpheader(Content-type,application/vnd.ms-excel) %mfs_httpheader(Content-Type,application/vnd.ms-excel)
%mfs_httpheader(Content-disposition,%str(attachment; filename=&outname)) %mfs_httpheader(Content-disposition,%str(attachment; filename=&outname))
%end; %end;
%end; %end;
%else %if &contentype=GIF or &contentype=JPEG or &contentype=PNG %then %do; %else %if &contentype=GIF or &contentype=JPEG or &contentype=PNG %then %do;
%if (&platform=SASMETA and &streamweb=1) %then %do; %if (&platform=SASMETA and &streamweb=1) %then %do;
data _null_; data _null_;
rc=stpsrv_header('Content-type',"image/%lowcase(&contenttype)"); rc=stpsrv_header('Content-Type',"image/%lowcase(&contenttype)");
run; run;
%end; %end;
%else %if &platform=SASVIYA %then %do; %else %if &platform=SASVIYA %then %do;
@@ -101,30 +110,30 @@ run;
contenttype="image/%lowcase(&contenttype)"; contenttype="image/%lowcase(&contenttype)";
%end; %end;
%else %if &platform=SASJS %then %do; %else %if &platform=SASJS %then %do;
%mfs_httpheader(Content-type,image/%lowcase(&contenttype)) %mfs_httpheader(Content-Type,image/%lowcase(&contenttype))
%end; %end;
%end; %end;
%else %if &contentype=HTML %then %do; %else %if &contentype=HTML or &contenttype=MARKDOWN %then %do;
%if (&platform=SASMETA and &streamweb=1) %then %do; %if (&platform=SASMETA and &streamweb=1) %then %do;
data _null_; data _null_;
rc=stpsrv_header('Content-type','text/html'); rc=stpsrv_header('Content-Type',"text/%lowcase(&contenttype)");
rc=stpsrv_header('Content-disposition',"attachment; filename=&outname"); rc=stpsrv_header('Content-disposition',"attachment; filename=&outname");
run; run;
%end; %end;
%else %if &platform=SASVIYA %then %do; %else %if &platform=SASVIYA %then %do;
filename &outref filesrvc parenturi="&SYS_JES_JOB_URI" name="_webout.json" filename &outref filesrvc parenturi="&SYS_JES_JOB_URI" name="_webout.json"
contenttype="text/html" contenttype="text/%lowcase(&contenttype)"
contentdisp="attachment; filename=&outname"; contentdisp="attachment; filename=&outname";
%end; %end;
%else %if &platform=SASJS %then %do; %else %if &platform=SASJS %then %do;
%mfs_httpheader(Content-type,text/html) %mfs_httpheader(Content-Type,text/%lowcase(&contenttype))
%mfs_httpheader(Content-disposition,%str(attachment; filename=&outname)) %mfs_httpheader(Content-disposition,%str(attachment; filename=&outname))
%end; %end;
%end; %end;
%else %if &contentype=TEXT %then %do; %else %if &contentype=TEXT %then %do;
%if (&platform=SASMETA and &streamweb=1) %then %do; %if (&platform=SASMETA and &streamweb=1) %then %do;
data _null_; data _null_;
rc=stpsrv_header('Content-type','application/text'); rc=stpsrv_header('Content-Type','application/text');
rc=stpsrv_header('Content-disposition',"attachment; filename=&outname"); rc=stpsrv_header('Content-disposition',"attachment; filename=&outname");
run; run;
%end; %end;
@@ -134,14 +143,14 @@ run;
contentdisp="attachment; filename=&outname"; contentdisp="attachment; filename=&outname";
%end; %end;
%else %if &platform=SASJS %then %do; %else %if &platform=SASJS %then %do;
%mfs_httpheader(Content-type,application/text) %mfs_httpheader(Content-Type,application/text)
%mfs_httpheader(Content-disposition,%str(attachment; filename=&outname)) %mfs_httpheader(Content-disposition,%str(attachment; filename=&outname))
%end; %end;
%end; %end;
%else %if &contentype=WOFF or &contentype=WOFF2 or &contentype=TTF %then %do; %else %if &contentype=WOFF or &contentype=WOFF2 or &contentype=TTF %then %do;
%if (&platform=SASMETA and &streamweb=1) %then %do; %if (&platform=SASMETA and &streamweb=1) %then %do;
data _null_; data _null_;
rc=stpsrv_header('Content-type',"font/%lowcase(&contenttype)"); rc=stpsrv_header('Content-Type',"font/%lowcase(&contenttype)");
run; run;
%end; %end;
%else %if &platform=SASVIYA %then %do; %else %if &platform=SASVIYA %then %do;
@@ -149,13 +158,13 @@ run;
contenttype="font/%lowcase(&contenttype)"; contenttype="font/%lowcase(&contenttype)";
%end; %end;
%else %if &platform=SASJS %then %do; %else %if &platform=SASJS %then %do;
%mfs_httpheader(Content-type,font/%lowcase(&contenttype)) %mfs_httpheader(Content-Type,font/%lowcase(&contenttype))
%end; %end;
%end; %end;
%else %if &contentype=XLSX %then %do; %else %if &contentype=XLSX %then %do;
%if (&platform=SASMETA and &streamweb=1) %then %do; %if (&platform=SASMETA and &streamweb=1) %then %do;
data _null_; data _null_;
rc=stpsrv_header('Content-type', rc=stpsrv_header('Content-Type',
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'); 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
rc=stpsrv_header('Content-disposition',"attachment; filename=&outname"); rc=stpsrv_header('Content-disposition',"attachment; filename=&outname");
run; run;
@@ -167,7 +176,7 @@ run;
contentdisp="attachment; filename=&outname"; contentdisp="attachment; filename=&outname";
%end; %end;
%else %if &platform=SASJS %then %do; %else %if &platform=SASJS %then %do;
%mfs_httpheader(Content-type %mfs_httpheader(Content-Type
,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet ,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
) )
%mfs_httpheader(Content-disposition,%str(attachment; filename=&outname)) %mfs_httpheader(Content-disposition,%str(attachment; filename=&outname))
@@ -176,7 +185,7 @@ run;
%else %if &contentype=ZIP %then %do; %else %if &contentype=ZIP %then %do;
%if (&platform=SASMETA and &streamweb=1) %then %do; %if (&platform=SASMETA and &streamweb=1) %then %do;
data _null_; data _null_;
rc=stpsrv_header('Content-type','application/zip'); rc=stpsrv_header('Content-Type','application/zip');
rc=stpsrv_header('Content-disposition',"attachment; filename=&outname"); rc=stpsrv_header('Content-disposition',"attachment; filename=&outname");
run; run;
%end; %end;
@@ -186,7 +195,7 @@ run;
contentdisp="attachment; filename=&outname"; contentdisp="attachment; filename=&outname";
%end; %end;
%else %if &platform=SASJS %then %do; %else %if &platform=SASJS %then %do;
%mfs_httpheader(Content-type,application/zip) %mfs_httpheader(Content-Type,application/zip)
%mfs_httpheader(Content-disposition,%str(attachment; filename=&outname)) %mfs_httpheader(Content-disposition,%str(attachment; filename=&outname))
%end; %end;
%end; %end;