<commit_before>#lang scheme/base

(require (file "util.scm")
         (file "web-support.scm")
         "settings.scm")

(provide save-uploaded-file!)

(declare-setting *PATH_TO_FILEDATA* (build-path (current-directory) "filedata"))

(define (save-uploaded-file! file-data)
  (let* ((filename (fresh-filename-id (binding/string:file-filename file-data)))
        (raw-file-bytes (binding/string:file-content file-data))
        (fport (open-output-file (build-path (setting *PATH_TO_FILEDATA*) filename) #:exists 'error)))
    (write-bytes raw-file-bytes fport)
    (close-output-port fport)
    filename))

(define (fresh-filename-id filename #:id-length (id-length 5))
  (let ((try (string-append (random-key-string id-length) "-" filename)))
    (if (file-exists? (build-path *PATH_TO_FILEDATA* try))
        (fresh-filename-id filename #:id-length id-length)
        try)))
<commit_msg>*PATH_TO_FILEDATA* is a setting, so we need to access it as such<commit_after>#lang scheme/base

(require (file "util.scm")
         (file "web-support.scm")
         "settings.scm")

(provide save-uploaded-file!)

(declare-setting *PATH_TO_FILEDATA* (build-path (current-directory) "filedata"))

(define (save-uploaded-file! file-data)
  (let* ((filename (fresh-filename-id (binding/string:file-filename file-data)))
        (raw-file-bytes (binding/string:file-content file-data))
        (fport (open-output-file (build-path (setting *PATH_TO_FILEDATA*) filename) #:exists 'error)))
    (write-bytes raw-file-bytes fport)
    (close-output-port fport)
    filename))

(define (fresh-filename-id filename #:id-length (id-length 5))
  (let ((try (string-append (random-key-string id-length) "-" filename)))
    (if (file-exists? (build-path (setting *PATH_TO_FILEDATA*) try))
        (fresh-filename-id filename #:id-length id-length)
        try)))

{'fraction_non_alphanumeric': 0.16241173275393808, 'fraction_numerical': 0.0010863661053775121, 'mean_word_length': 3.8346456692913384, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '279018', 'n_tokens_mistral': 632, 'n_tokens_neox': 624, 'n_words': 136}