async create(request) {
        const sourceDir = path.join(path.dirname(new URL(import.meta.url).pathname), '../../compute-source-code');
        const files = await this.loadFiles(sourceDir);
        const result = {
            added: [],
            updated: [],
        };

        for (const [ filename, sourceText ] of files.entries()) {
            const relativePath = filename.substring(sourceDir.length + 1);

            const dbFile = await this.db.sourceCode({
                specifier: relativePath,
            }).findOne();

            if (dbFile) {
                dbFile.sourceText = sourceText;
                await dbFile.save();
                result.updated.push(relativePath);
            } else {
                await new this.db.sourceCode({
                    specifier: relativePath,
                    sourceText,
                }).save();
                result.added.push(relativePath);
            }
        }

        request.response().status(201).send({
            files: result,
        });
    }
/**
    * add source code to the db
    */
add source code to the db
add source code to the db
async create(request) {
        const sourceDir = path.join(path.dirname(new URL(import.meta.url).pathname), '../../compute-source-code');
        const files = await this.loadFiles(sourceDir);
        const result = {
            added: [],
            updated: [],
        };
        for (const [ filename, sourceText ] of files.entries()) {
            const relativePath = filename.substring(sourceDir.length + 1);
            const dbFile = await this.db.sourceCode({
                specifier: relativePath,
            }).findOne();
            if (dbFile) {
                dbFile.sourceText = sourceText;
                await dbFile.save();
                result.updated.push(relativePath);
            } else {
                await new this.db.sourceCode({
                    specifier: relativePath,
                    sourceText,
                }).save();
                result.added.push(relativePath);
            }
        }
        request.response().status(201).send({
            files: result,
        });
    }
async create ( request ) { const sourceDir = path . join ( path . dirname ( new URL ( import . meta . url ) . pathname ) , '../../compute-source-code' ) ; const files = await this . loadFiles ( sourceDir ) ; const result = { added : [ ] , updated : [ ] , } ; for ( const [ filename , sourceText ] of files . entries ( ) ) { const relativePath = filename . substring ( sourceDir . length + 1 ) ; const dbFile = await this . db . sourceCode ( { specifier : relativePath , } ) . findOne ( ) ; if ( dbFile ) { dbFile . sourceText = sourceText ; await dbFile . save ( ) ; result . updated . push ( relativePath ) ; } else { await new this . db . sourceCode ( { specifier : relativePath , sourceText , } ) . save ( ) ; result . added . push ( relativePath ) ; } } request . response ( ) . status ( 201 ) . send ( { files : result , } ) ; }
add source code to the db
add source code to the db