Loading...
'; echo ''; } ?>
Leave feedback 1/4
Please leave feedback here to help us make this site better; you can choose to be anonymous.
We look over the feedback to know how we can improve the site and get what users want.
 
Do you want to be anonymous when leaving feedback?
Check for Yes
Next
Leave feedback 2/4
What is your overall impression of the layout?
Terrible AWESOME!!!
 
How easy is it to navigate the site?
Extremely easy How do I get out of here?
Next
Leave feedback 3/4
What is your overall impression of the functionality?
You call that functionality? Excellent!
 
How easy was it to understand what the site is about?
I still have no clue. I knew it before I came here!
Next
Leave feedback 4/4
Leave comments or suggestions here.
Send
Something went wrong; please check that you have marked all questions.
Start Forum Posts Leaderboard More















Mutation

Logged Out
Leaderboard coming soon

Engineering Solutions for the Church

Christian Engineering Solutions (CES) is a Not for Profit Organization specializing in collaborative solutions development for the Church. In the Spirit of Jesus Christ, we are to spread the gospel throughout the Earth, taking care to be good examples of Christ Jesus by serving others. CES is designed to help the Church meet these goals in the most rigorous manner possible.

Our Technology

Our Technology is scripture based in its goals and foundations. Open-Source and Free, one may use our services to both learn and solve problems with the goals of helping others and growing closer to God.

Features

Merit-based Reputation and Rewards

Streamlined Search and Citations

Modular Applications

Peer-to-Peer and Encryption Technologies (Under Development)

External Repository

https://github.com/ChristianEngineeringSolutions/ChristianEngineeringSolutions


Setup Account with email to earn rewards from reputation and donations.
Projects/Source Code/controllers/
passageController.js
Comments

ADMIN
One Way , 8/8/2024
   Project in Projects/Source Code/controllers/
"use strict";
const Passage = require('../models/Passage');
//Call in Scripts
const scripts = {};
var fs = require('fs'); 

module.exports = {
    deletePassage: async function(req, res, callback) {
        let passageID = req.body._id;
        let passage = await Passage.findOne({_id: passageID});
        if(passage.author._id.toString() != req.session.user._id.toString()){
            return res.send("Only passage author can delete.");
        }
        //delete uploads too
        for(const filename of passage.filename){
            //make sure no other passages are using the file
            var passages = await Passage.find({
                filename: {
                    $in: [filename]
                }
            });
            if(passages.length == 1){
                var where = passage.personal ? 'protected': 'uploads';
                fs.unlink('dist/'+where+'/'+filename, function(err){
                    if (err && err.code == 'ENOENT') {
                        // file doens't exist
                        console.info("File doesn't exist, won't remove it.");
                    } else if (err) {
                        // other errors, e.g. maybe we don't have enough permission
                        console.error("Error occurred while trying to remove file");
                    } else {
                        console.info(`removed upload for deleted passage`);
                    }
                });
            }
        }
        await Passage.deleteOne({_id: passageID.trim()});
        callback();
        // async function deleteRecursively(passage, arrToDelete){
        //     var arrToDelete = [];
        //     //delete uploads too
        //     for(const filename of passage.filename){
        //         //make sure no other passages are using the file
        //         var passages = await Passage.find({
        //             filename: {
        //                 $in: [filename]
        //             }
        //         });
        //         if(passages.length == 1){
        //             var where = passage.personal ? 'protected': 'uploads';
        //             fs.unlink('dist/'+where+'/'+filename, function(err){
        //                 if (err && err.code == 'ENOENT') {
        //                     // file doens't exist
        //                     console.info("File doesn't exist, won't remove it.");
        //                 } else if (err) {
        //                     // other errors, e.g. maybe we don't have enough permission
        //                     console.error("Error occurred while trying to remove file");
        //                 } else {
        //                     console.info(`removed upload for deleted passage`);
        //                 }
        //             });
        //         }
        //     }
        //     for(const p of passage.passages){
        //         arrToDelete.push(p._id);
        //         deleteRecursively(p, arrToDelete);
        //     }
        //     for(const p of arrToDelete){
        //         await Passage.deleteOne({_id: p._id()});
        //     }
        //     await Passage.deleteOne({_id: passage._id()});
        // }
    },
    copyPassage: async function(passage, user, parent, callback, synthetic=false){
        //add source
        let sourceList = passage.sourceList;
        sourceList.push(passage._id);
        //duplicate main passage
        let copy = await Passage.create({
            parent: parent,
            author: user[0],
            users: user,
            sourceList: sourceList,
            title: passage.title,
            content: passage.content,
            html: passage.html,
            css: passage.css,
            javascript: passage.javascript,
            filename: passage.filename,
            code: passage.code,
            lang: passage.lang,
            isSVG: passage.isSVG,
            license: passage.license,
            mimeType: passage.mimeType,
            thumbnail: passage.thumbnail,
            metadata: passage.metadata,
            sourceLink: passage.sourceLink,
            personal: passage.personal,
            synthetic: synthetic,
            mirror: passage.mirror,
            bestOf: passage.bestOf,
            mirrorEntire: passage.mirrorEntire,
            mirrorContent: passage.mirrorContent,
            bestOfEntire: passage.bestOfEntire,
            bestOfContent: passage.bestOfContent
        });
        //Add copy to passage it was duplicated into
        if(parent != "root" && parent != null){
            let parentPassage = await Passage.findOne({_id: parent});
            copy.parent = parentPassage;
            parentPassage.passages.push(copy);
            await copy.save();
            await parentPassage.save();
        }
        //copy children
        async function copyPassagesRecursively(passage, copy){
            let copySubPassages = [];
            for(const p of passage.passages){
                let sourceList = p.sourceList;
                sourceList.push(p._id);
                let pcopy = await Passage.create({
                    author: user[0],
                    users: user,
                    parent: copy,
                    sourceList: sourceList,
                    title: p.title,
                    content: p.content,
                    html: p.html,
                    css: p.css,
                    javascript: p.javascript,
                    filename: p.filename,
                    code: p.code,
                    lang: p.lang,
                    isSVG: p.isSVG,
                    license: p.license,
                    mimeType: p.mimeType,
                    thumbnail: p.thumbnail,
                    metadata: p.metadata,
                    sourceLink: p.sourceLink,
                    synthetic: synthetic,
                    personal: p.personal
                });
                copy.passages.push(pcopy._id);
                await copy.save();
                if(p.passages){
                    await copyPassagesRecursively(p, pcopy);
                }
            }
            // console.log(copy.title);
            let update = await Passage.findOneAndUpdate({_id: copy._id}, {
                passages: copy.passages
            }, {
                new: true
            });
            let check = await Passage.findOne({_id: copy._id});
            return update;
            // console.log(done.title + '\n' + done.passages[0]);
        }
        let result = '';
        if(passage.passages.length >= 1){
            let result = await copyPassagesRecursively(passage, copy);
        }
        else{
            console.log('false');
        }
        let ret = await Passage.findOne({_id: copy._id}).populate('author users sourceList');
        return ret;
        // res.render('passage', {passage: copy, sub: true});
    },
}

0 Stars