@@ -33,14 +33,14 @@ async function init(options) {
3333async function preload ( options ) {
3434 await init ( ) ;
3535
36- const { packages, files, context_id} = options ;
36+ const { packages, files, context_id, root_url } = options ;
3737
3838 if ( packages ) {
3939 self . pyodide . loadPackage ( packages ) ;
4040 }
4141
4242 if ( files ) {
43- load_files ( files , context_id ) ;
43+ load_files ( root_url , files , context_id ) ;
4444 }
4545}
4646
@@ -71,24 +71,27 @@ function use_context(context_id) {
7171 init_filesystem ( default_context . files . concat ( context . files ) ) ;
7272}
7373
74- /**
75- * Load a file from the question resources, and return a blob which can be used in the worker's resources filesystem.
76- *
77- * @param {string } name
78- * @returns {Object } ``name`` and ``data: Blob``.
79- */
80- async function load_file ( name ) {
81- const res = await fetch ( '../../../resources/question-resources/' + name ) ;
82- const blob = await res . blob ( ) ;
83- return { name, data : blob } ;
84- }
85-
8674/**
8775 * Load a list of files from the question resources, and store them in the context with the given ID.
8876 */
89- async function load_files ( filenames , context_id ) {
77+ async function load_files ( root_url , filenames , context_id ) {
9078 const context = get_context ( context_id ) ;
9179
80+ root_url += 'resources/question-resources/' ;
81+
82+ /**
83+ * Load a file from the question resources, and return a blob which can be used in the worker's resources filesystem.
84+ *
85+ * @param {string } name
86+ * @returns {Object } ``name`` and ``data: Blob``.
87+ */
88+ async function load_file ( name ) {
89+ const url = root_url + name ;
90+ const res = await fetch ( url ) ;
91+ const data = await res . blob ( ) ;
92+ return { name, data} ;
93+ }
94+
9295 await Promise . all ( filenames . map ( async name => {
9396 const file = await load_file ( name ) ;
9497 context . files . push ( file ) ;
0 commit comments