aboutsummaryrefslogtreecommitdiff
path: root/captain
diff options
context:
space:
mode:
authorJeffrey Armstrong <jeff@approximatrix.com>2022-06-29 08:40:04 -0400
committerJeffrey Armstrong <jeff@approximatrix.com>2022-06-29 08:40:04 -0400
commit10247d7db2aaffdc617066fa261de8df6454e966 (patch)
treea5a17fde9904b27e57fa51357cbd8ae1cfe0f8d9 /captain
parent6f681035a7c7125a72ce04d6881c1579bdb96d09 (diff)
parentfb7136be64188cab7db34ac3ad6c8f27098173de (diff)
downloadlevitating-10247d7db2aaffdc617066fa261de8df6454e966.tar.gz
levitating-10247d7db2aaffdc617066fa261de8df6454e966.zip
Merge branch 'artifacts'
Diffstat (limited to 'captain')
-rw-r--r--captain/db.f9077
-rw-r--r--captain/external.f908
-rw-r--r--captain/special.f9034
-rw-r--r--captain/sql/create.sql1
-rw-r--r--captain/web.f9021
5 files changed, 140 insertions, 1 deletions
diff --git a/captain/db.f90 b/captain/db.f90
index 90fb4e1..c3f30c4 100644
--- a/captain/db.f90
+++ b/captain/db.f90
@@ -1747,5 +1747,82 @@ contains
end function is_valid_session_db
+ subroutine add_job_upload_db(job_id, category, filename)
+ implicit none
+
+ integer, intent(in)::job_id
+ character(len=*), intent(in)::category, filename
+
+ type(sqlite3_stmt)::stmt
+
+ if(stmt%prepare(db, "INSERT INTO job_uploads(job, category, filename) VALUES(?, ?, ?)") == SQLITE_OK) then
+
+ if(stmt%bind_int(1, job_id) == SQLITE_OK .and. stmt%bind_text(2, category) == SQLITE_OK .and. &
+ stmt%bind_text(3, filename) == SQLITE_OK) &
+ then
+
+ call stmt%step_now()
+
+ end if
+ call stmt%finalize()
+ end if
+
+ end subroutine add_job_upload_db
+
+ function get_job_upload_count_by_category_db(job_id, category) result(entries)
+ implicit none
+
+ integer, intent(in)::job_id
+ character(len=*), intent(in)::category
+ integer::entries
+ type(sqlite3_stmt)::stmt
+
+ entries = 0
+
+ if(stmt%prepare(db, "SELECT COUNT(*) FROM job_uploads WHERE job=? AND category=?") == SQLITE_OK) then
+ if(stmt%bind_int(1, job_id) == SQLITE_OK .and. stmt%bind_text(2, category) == SQLITE_OK) then
+ if(stmt%step() == SQLITE_ROW) then
+ entries = stmt%column_int(0)
+ end if
+ end if
+ call stmt%finalize()
+ end if
+
+ end function get_job_upload_count_by_category_db
+
+ function get_job_uploads_by_category_db(job_id, category, count) result(res)
+ implicit none
+
+ integer, intent(in)::job_id
+ character(len=*), intent(in)::category
+ integer, intent(out), optional::count
+
+ character(len=FILENAME_NAME_LENGTH), dimension(:), pointer::res
+
+ type(sqlite3_stmt)::stmt
+ integer::entries, i
+
+ res => null()
+ entries = get_job_upload_count_by_category_db(job_id, category)
+
+ if(entries > 0) then
+ allocate(res(entries))
+
+ i = 1
+ if(stmt%prepare(db, "SELECT filename FROM job_uploads WHERE job=? AND category=?") == SQLITE_OK) then
+ if(stmt%bind_int(1, job_id) == SQLITE_OK .and. stmt%bind_text(2, category) == SQLITE_OK) then
+ do while(stmt%step() == SQLITE_ROW)
+ call stmt%column_text(0, res(i))
+ i = i + 1
+ end do
+ end if
+ end if
+ end if
+
+ if(present(count)) then
+ count = entries
+ end if
+
+ end function get_job_uploads_by_category_db
end module captain_db
diff --git a/captain/external.f90 b/captain/external.f90
index 6fd848c..766bd2e 100644
--- a/captain/external.f90
+++ b/captain/external.f90
@@ -1040,7 +1040,7 @@ contains
end if
if(associated(fullpath)) then
-
+
! Write the file
call write_log("Storing titan file to "//trim(fullpath), LOG_DEBUG)
@@ -1050,6 +1050,12 @@ contains
call resp%set_body_contents(RESPONSE_JSON_OKAY)
resp%body_mimetype = "text/plain"
+ if(req%q%has_key("job")) then
+ call write_log("Ok, log")
+ call report_upload(req)
+ call write_log("Upload logged?")
+ end if
+
else
resp%code = GEMINI_CODE_TEMPFAIL
diff --git a/captain/special.f90 b/captain/special.f90
index 553378e..4d8640f 100644
--- a/captain/special.f90
+++ b/captain/special.f90
@@ -129,4 +129,38 @@ contains
end function get_full_filename_from_request
+ subroutine report_upload(req)
+ use captain_db
+ use server_response
+ use logging
+ implicit none
+
+ class(request), intent(in)::req
+ integer::job_id, ierr
+ character(len=:), pointer:: job_text
+
+ character(256)::first
+ character(1024)::remaining
+ integer::i
+
+ job_text => req%q%get_value("job")
+ call write_log("jobtext: "//trim(job_text))
+ if(associated(job_text)) then
+ read(job_text, *, iostat=ierr) job_id
+ if(ierr == 0) then
+ call write_log("jobid ok")
+ call req%path_component(1, first)
+ i = index(req%location, trim(first))
+ i = i + len_trim(first) + 1
+ remaining = req%location(i:len_trim(req%location))
+
+
+ call write_log("Writing job upload for: "//trim(first)//" -> "//trim(remaining))
+ call add_job_upload_db(job_id, trim(first), trim(remaining))
+
+ end if
+ end if
+
+ end subroutine report_upload
+
end module special_filenames
diff --git a/captain/sql/create.sql b/captain/sql/create.sql
index 323efd0..f8c674f 100644
--- a/captain/sql/create.sql
+++ b/captain/sql/create.sql
@@ -25,3 +25,4 @@ CREATE TABLE sessions(user INTEGER, session TEXT NOT NULL, accessed TEXT NOT NUL
CREATE VIEW session_auth AS SELECT sessions.session, users.username, users.level FROM sessions INNER JOIN users ON sessions.user = users.id;
+CREATE TABLE job_uploads(job INTEGER, category TEXT NOT NULL, filename TEXT NOT NULL, FOREIGN KEY(job) REFERENCES jobs(id));
diff --git a/captain/web.f90 b/captain/web.f90
index 1421f96..3b94379 100644
--- a/captain/web.f90
+++ b/captain/web.f90
@@ -746,6 +746,7 @@ contains
function generate_one_job_html(req) result(res)
use captain_db
+ use config
use server_response
use special_filenames, only: get_task_result_static_filename
use request_utils, only: get_status_utf8, get_player_link => player_link, &
@@ -766,6 +767,7 @@ contains
character(len=:), pointer::task_results_filename, one_link, local_task_results_filename
character(len=:), pointer::player_link, instruction_link
+ character(len=FILENAME_NAME_LENGTH), dimension(:), pointer::releases
logical::file_exists
res => null()
@@ -834,6 +836,25 @@ contains
res = trim(res)//nl//nl//"<p><strong>None reported yet</strong></p>"
end if
+ if(get_job_upload_count_by_category_db(job_id, "releases") > 0 .and. &
+ req%auth_level >= global_permissions%get("access-releases")) &
+ then
+
+ res = trim(res)//nl//"<h3>Releases</h3>"//nl//"<ul>"
+ releases => get_job_uploads_by_category_db(job_id, "releases")
+ do i = 1, size(releases)
+
+ one_link => html_link("/releases/"//trim(releases(i)), &
+ trim(releases(i)))
+
+ res = trim(res)//nl//" <li>"//trim(one_link)//"</li>"
+
+ end do
+
+ res = trim(res)//nl//"</ul>"
+
+ end if
+
else
allocate(character(len=64) :: res)