Skip to content

File Creation

Asher Dale edited this page Nov 10, 2021 · 9 revisions

Because ClassTranscribe has a large amount of files, we are working on organizing CT's files into a structure to prevent too many files existing in a single directory. To do so, each file will be located in a subdirectory based on the Course and CourseOffering that it is related to.

When a Course or CourseOffering is created, a new string called FilePath will be computed in the following manner: yymmxxxx, where yy is the two digit year, mm is the two digit month, and xxxx are four random alphanumeric characters. This field will dictate the subdirectory that related files are placed into. The Course's FilePath will be the parent directory and the CourseOffering's FilePath will be a child directory. To prevent extra lookups, we will include the Course FilePath in the CourseOffering FilePath. These FilePath values will be stored in the database with their respective entities, so they will only need to be computed once, upon creation of the entity. The following is an example:

  1. A Course object is created and is assigned the FilePath value of 2104yF3d.
  2. A CourseOffering object is created for the above course. The computed FilePath for the CourseOffering is 2104yF3d/2105Kpl9.
  3. A video file is uploaded for the above course offering, and it is stored in the directory 2104yF3d/2105Kpl9 on the filesystem.

When the FilePath values are computed during Course and CourseOffering creation, we will create the directories on the filesystem at this time so we will not have to check for existence of the directories at later times. Additionally, this will allow us to check for any collisions in the directory names.

Creating a file in the backend is a three step process:

  1. Call the GetTmpFile function in CommonUtils.cs to create a temporary file in the "temp" folder.
  2. Write the contents of the file to the new temp file.
  3. Call the GetNewFileRecordAsync function in FileRecord.cs, which will move the temp file to a new file that will be placed in a subdirectory based on the Course and CourseOffering that it is related to. A valid CourseOffering must be passed in to this function.

If a new file is provided with the contents already in it (such as when a user uploads a video or an image), then only step 3 is required.

Currently, all existing Courses and CourseOfferings do not have the computed FilePath fields, so in the PR for implementing these changes I will include a small script in the DB migration for computing these values for all existing Courses and CourseOfferings.

Clone this wiki locally