Commit 61de876c authored by Jerome Chauveau's avatar Jerome Chauveau
Browse files

Premier jet du plugin d'export des sources - ticket #100

parent 66dc05e4
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -5,3 +5,4 @@
/configuration/configuration.xml
.idea
.DS_Store
/plugins/**/.ignore
 No newline at end of file
+38 −0
Original line number Diff line number Diff line
xquery version "3.0";

module namespace max.plugin.sources_export = 'pddn/max/plugin/sources_export';
import module namespace max.config = 'pddn/max/config' at '../../rxq/config.xqm';


declare
%rest:GET
%output:media-type('application/octet-stream')
%rest:path("/{$project}/export")
function max.plugin.sources_export:export($project){
    let $db := max.config:getProjectDBPath($project)
    let $tmpDir := file:create-temp-dir('max-export',$project)
    let $zipName := $project||'.zip'
    let $dest := $tmpDir ||'/'||$zipName
    return (
            db:export($db, $tmpDir),
            max.plugin.sources_export:makeZip($project,$tmpDir, $dest),
            (<rest:response>
                <http:response status="200">
                    <http:header name="content-type" value="application/octet-stream"/>
                    <http:header name="Content-Disposition" value="attachment; filename={$zipName}"/>
                </http:response>
            </rest:response>,
            file:read-binary($dest)
            ),
            file:delete($tmpDir,true())
        )
};

declare %private function max.plugin.sources_export:makeZip($project,$directory, $dest){
    let $files := file:list($directory, true(), '*.xml')
    let $zip   := archive:create($files,
            for $file in $files
            return file:read-binary($directory || $file)
    )
    return file:write-binary($dest, $zip)
};
 No newline at end of file