!C99Shell v. 2.5 [PHP 8 Update] [24.05.2025]!

Software: Apache/2.4.41 (Ubuntu). PHP/8.0.30 

uname -a: Linux apirnd 5.4.0-204-generic #224-Ubuntu SMP Thu Dec 5 13:38:28 UTC 2024 x86_64 

uid=33(www-data) gid=33(www-data) groups=33(www-data) 

Safe-mode: OFF (not secure)

/var/www/html/wincloud_gateway/node_modules/strapi-connector-bookshelf/lib/utils/   drwxr-xr-x
Free 13.19 GB of 57.97 GB (22.76%)
Home    Back    Forward    UPDIR    Refresh    Search    Buffer    Encoder    Tools    Proc.    FTP brute    Sec.    SQL    PHP-code    Update    Self remove    Logout    


Viewing file:     populate-queries.js (2.9 KB)      -rw-r--r--
Select action/file-type:
(+) | (+) | (+) | Code (+) | Session (+) | (+) | SDB (+) | (+) | (+) | (+) | (+) | (+) |
'use strict';

const _ = require('lodash');
const {
  contentTypes: {
    hasDraftAndPublish,
    constants: { DP_PUB_STATE_LIVE, DP_PUB_STATE_PREVIEW, PUBLISHED_AT_ATTRIBUTE },
  },
} = require('strapi-utils');

const optionsMap = {
  publicationState: {
    queries: {
      [DP_PUB_STATE_LIVE]: ({ model, alias }) => qb => {
        const { collectionName } = model;
        qb.whereNotNull(`${alias || collectionName}.${PUBLISHED_AT_ATTRIBUTE}`);
      },
      [DP_PUB_STATE_PREVIEW]: () => null,
    },
    validate({ model, query: publicationState }) {
      return hasDraftAndPublish(model) && _.has(this.queries, publicationState);
    },
  },
};

const isValidOption = optionName => _.has(optionsMap, optionName);

const validate = (optionName, params) => {
  const opt = _.get(optionsMap, optionName, {});
  return !_.isFunction(opt.validate) || opt.validate(params);
};

const resolveQuery = (option, params) => optionsMap[option].queries[params.query](params);

/**
 * Transform given options to populate queries based on the optionsMap
 * @param options
 * @returns Array<Function>
 */
const toQueries = options => {
  return Object.keys(options).reduce((acc, key) => {
    const params = options[key];

    if (isValidOption(key) && validate(key, params)) {
      const query = resolveQuery(key, params);
      if (_.isFunction(query)) {
        return [...acc, query];
      }
    }
    return acc;
  }, []);
};

/**
 * Execute each query based on the query builder (qb) passed as argument
 * @param queries
 * @param qb
 */
const runPopulateQueries = (queries, qb) => {
  qb.where(qb => queries.forEach(query => query(qb)));
};

/**
 * Return an object which associates each given path to a populateQueries's runner
 * @param paths
 * @param options
 * @returns {*}
 */
const bindPopulateQueries = (paths, options) => {
  const queries = toQueries(options);
  const qbFn = qb => {
    runPopulateQueries(queries, qb);
  };

  return paths.reduce((acc, path) => ({ ...acc, [path]: qbFn }), {});
};

/**
 * Extend the behavior of an already existing populate query, and bind generated (from options) ones to it
 * @param fns
 * @param options
 * @returns {function(...[*]=)}
 */
const extendWithPopulateQueries = (fns, options) => {
  const queries = toQueries(options);

  return qb => {
    fns.filter(_.isFunction).forEach(fn => fn(qb));
    runPopulateQueries(queries, qb);
  };
};

/**
 * Transforms queryOptions (e.g { publicationState: 'live' })
 * into query map
 * {
 *   publicationState: { query: 'live', ...context }
 * }
 * @param {{ [key: string]: string }} queryOptions
 * @param {object} context
 */
const queryOptionsToQueryMap = (queryOptions, context) => {
  return Object.keys(queryOptions).reduce((acc, key) => {
    acc[key] = { query: queryOptions[key], ...context };
    return acc;
  }, {});
};

module.exports = {
  toQueries,
  runPopulateQueries,
  bindPopulateQueries,
  extendWithPopulateQueries,
  queryOptionsToQueryMap,
};

:: Command execute ::

Enter:
 
Select:
 

:: Search ::
  - regexp 

:: Upload ::
 
[ Read-Only ]

:: Make Dir ::
 
[ Read-Only ]
:: Make File ::
 
[ Read-Only ]

:: Go Dir ::
 
:: Go File ::
 

--[ c99shell v. 2.5 [PHP 8 Update] [24.05.2025] | Generation time: 0.0507 ]--