Skip to content

Commit 7c2b25e

Browse files
committed
fix to return release candidates for specified version
1 parent fbc0a1c commit 7c2b25e

File tree

1 file changed

+32
-18
lines changed

1 file changed

+32
-18
lines changed

server/endpoint_packages.pas

+32-18
Original file line numberDiff line numberDiff line change
@@ -625,37 +625,51 @@ function TFHIRPackageWebServer.logId: string;
625625
procedure TFHIRPackageWebServer.serveDownload(id, version : String; response : TIdHTTPResponseInfo);
626626
var
627627
conn : TFDBConnection;
628+
procedure sendRow;
629+
var
630+
pvk : integer;
631+
begin
632+
response.ResponseNo := 200;
633+
response.ResponseText := 'OK';
634+
response.ContentType := 'application/tar+gzip';
635+
response.ContentStream := TBytesStream.Create(conn.GetColBlobByName('Content'));
636+
response.ContentDisposition := 'attachment; filename="'+id+'#'+version+'.tgz"';
637+
response.FreeContentStream := true;
638+
pvk := conn.GetColIntegerByName('PackageVersionKey');
639+
conn.Terminate;
640+
conn.SQL := 'Update PackageVersions set DownloadCount = DownloadCount + 1 where PackageVersionKey = '+inttostr(pvk);
641+
conn.Prepare;
642+
conn.Execute;
643+
conn.Terminate;
644+
conn.SQL := 'Update Packages set DownloadCount = DownloadCount + 1 where Id = '''+SQLWrapString(id)+'''';
645+
conn.Prepare;
646+
conn.Execute;
647+
end;
628648
begin
629649
conn := FDB.getConnection('Package.server.download');
630650
try
631-
conn.SQL := 'Select Content from PackageVersions where Id = '''+SQLWrapString(id)+''' and Version = '''+SQLWrapString(version)+'''';
651+
conn.SQL := 'Select PackageVersionKey, Content from PackageVersions where Id = '''+SQLWrapString(id)+''' and Version = '''+SQLWrapString(version)+'''';
652+
conn.Prepare;
653+
conn.Execute;
654+
if conn.FetchNext then
655+
sendRow
656+
else
657+
begin
658+
conn.Terminate;
659+
conn.SQL := 'Select PackageVersionKey, Content from PackageVersions where Id = '''+SQLWrapString(id)+''' and Version like '''+SQLWrapString(version)+'-%'' order by PubDate desc';
632660
conn.Prepare;
633661
conn.Execute;
634662
if conn.FetchNext then
635-
begin
636-
response.ResponseNo := 200;
637-
response.ResponseText := 'OK';
638-
response.ContentType := 'application/tar+gzip';
639-
response.ContentStream := TBytesStream.Create(conn.GetColBlobByName('Content'));
640-
response.ContentDisposition := 'attachment; filename="'+id+'#'+version+'.tgz"';
641-
response.FreeContentStream := true;
642-
conn.Terminate;
643-
conn.SQL := 'Update PackageVersions set DownloadCount = DownloadCount + 1 where Id = '''+SQLWrapString(id)+''' and Version = '''+SQLWrapString(version)+'''';
644-
conn.Prepare;
645-
conn.Execute;
646-
conn.Terminate;
647-
conn.SQL := 'Update Packages set DownloadCount = DownloadCount + 1 where Id = '''+SQLWrapString(id)+'''';
648-
conn.Prepare;
649-
conn.Execute;
650-
end
663+
sendRow
651664
else
652665
begin
653666
response.ResponseNo := 404;
654667
response.ResponseText := 'Not found';
655668
response.ContentType := 'text/plain';
656669
response.ContentText := 'The package "'+id+'#'+version+'" is not known by this server';
657670
end;
658-
conn.Terminate;
671+
end;
672+
conn.Terminate;
659673
conn.release;
660674
except
661675
on e : Exception do

0 commit comments

Comments
 (0)