export async function uploadFile(file: File, requestConfig: AxiosRequestConfig = {}) { let allowedExtensions = getMeta("upload.allowedExtensions", []) as string[]; allowedExtensions = allowedExtensions.map((ext: string) => ext.toLowerCase()); const maxSize = getMeta("upload.maxSize", 0); const filePieces = file.name.split("."); const extension = filePieces[filePieces.length - 1] || ""; if (file.size > maxSize) { const humanSize = humanFileSize(maxSize); const stringTotal: string = humanSize.amount + humanSize.unitAbbr; const message = sprintf(t("The uploaded file was too big (max %s)."), stringTotal); throw new Error(message); } else if (!allowedExtensions.includes(extension.toLowerCase())) { const attachmentsString = allowedExtensions.join(", "); const message = sprintf( t( "The uploaded file did not have an allowed extension. \nOnly the following extensions are allowed. \n%s.", ), attachmentsString, ); throw new Error(message); } const data = new FormData(); data.append("file", file, file.name); const result = await apiv2.post("/media", data, requestConfig); return result.data; }
export function stringTime (input) { let min = Math.floor(input / (1000 * 60)); let sec = Math.floor((input - min * 60 * 1000) / 1000); let msec = input % 1000; if(msec) { if(min > 9) { return sprintf('%02d:%02d.%03d', min, sec, msec); } else { return sprintf('%01d:%02d.%03d', min, sec, msec); } } return sprintf('%02d:%02d', min, sec); }
fs.readFile(filename, (err, settingsBuffer: Buffer) => { var info = JSON.parse(settingsBuffer + ''), dependencyCount, devDependencyCount; if (err) { this.services.log.warn('package.json not present'); } else { dependencyCount = info.dependencies ? Object.keys(info.dependencies).length : 0; devDependencyCount = info.devDependencies ? Object.keys(info.devDependencies).length : 0; if (dependencyCount > 0 || devDependencyCount > 0) { this.services.log.startSection(sprintf('Installing %d npm dependencies (%d dev)', dependencyCount, devDependencyCount)); } else { this.services.log.startSection('Installing npm dependencies'); this.services.log.warn('package.json contains neither dependencies nor devDependencies'); } } this.services.shell.exec('npm install').then(() => { this.services.log.closeSection('Node packages installed'); deferred.resolve(true); }).fail(function (error) { deferred.reject(error); }); });
Object.keys(buildConfig[dirsKey][workingKey]).forEach((key) => { // determine the filename for the zip let zipFilename = sprintf("%s-%s%s-%s-%s.zip", buildConfig[packageKey][nameKey], options.version, flag, branch, key); let zipFilepath = pathJoin(buildConfig[dirsKey][outputKey], zipFilename); // zip up the files zip(buildConfig[dirsKey][workingKey][key], zipFilepath, (err) => { if (err) { console.log("##vso[task.logissue type=error]Packaging Failed: %s", err); } else { console.log("Packaging Successful: %s", zipFilename); // set a variable as the path to the zip_file, this can then be used in subsequent // tasks to add the zip to the artefacts console.log("##vso[task.setvariable variable=%s]%s", options.outputvar, zipFilepath); // remove the createUIdefinition file from the working dir as this will be uploaded to // blob storage and the API key should not be visible let uiDefinitionFile = pathJoin(buildConfig[dirsKey][workingKey][key], "createUiDefinition.json"); if (existsSync(uiDefinitionFile)) { console.log("Removing UI definition file: ", uiDefinitionFile); unlinkSync(uiDefinitionFile); } } }); });
execute(): Q.Promise<boolean> { var deferred = Q.defer<boolean>(), filename = sprintf('%s/%s/bower.json', this.services.config.paths.getTemp(), this.services.config.projectName); fs.readFile(filename, (err, settingsBuffer: Buffer) => { var info = JSON.parse(settingsBuffer + ''); if (err) { this.services.log.warn('bower.json not present'); } else { this.services.log.startSection(sprintf('Installing %d bower dependencies', Object.keys(info.dependencies).length)); } this.services.shell.exec('bower install').then( ()=> { this.services.log.closeSection('Bower packages installed'); deferred.resolve(true); }, (error) => { deferred.reject(error); }); }); return deferred.promise; }
execute() { var d = Q.defer(), filename = sprintf('%s/%s/composer.json', this.services.config.paths.getTemp(), this.services.config.projectName); fs.readFile(filename, (err, settingsBuffer: Buffer) => { var info = JSON.parse(settingsBuffer + ''); if (err) { this.services.log.startSection('Installing composer dependencies'); this.services.log.warn('composer.json not present'); } else { this.services.log.startSection(sprintf('Installing %d composer dependencies', Object.keys(info.require).length)); } this.services.shell.exec(this.services.config.globalConfig.composer.command + ' install --optimize-autoloader').then((stdout) => { this.services.log.closeSection('Composer dependencies installed'); d.resolve(true); }).fail(function (error) { d.reject(error); }); }); return d.promise; }
() => { var end = (new Date()).getTime(); this.serviceContainer.log.closeSection(sprintf( 'It took %ss to deploy "%s" to "%s". :)' + "\n\n", (0.001 * (end - start)).toFixed(3), config.projectName, config.stageName )); },
articles.forEach((item) => { var url = sprintf(config['rss']['urlfmt'], { 'id': item['id'] }); feed.item({ 'title': item['title'], 'description': item['summary'], 'url': url, 'guid': url, 'author': item['username'], 'date': item['post_date'] }); });
fp.discover().forEach(function (entry) { console.log(sprintf("%8d %-8s %-8s %-32s", entry.handle, entry.driver_type, entry.driver, entry.driver_detail)); if (verbose) { var reader = promise.promisifyAll(fp.get_reader(entry.handle)); console.log(sprintf("\t Enroll stages: %d", reader.enroll_stages)); console.log(sprintf("\t Supports imaging: %s", reader.supports_imaging)); console.log(sprintf("\t Supports identification: %s", reader.supports_identification)); console.log(sprintf("\t Image height: %d", reader.img_height)); console.log(sprintf("\t Image width: %d", reader.img_width)); reader.start_enrollAsync().then( function (result) { console.log(result); } ) .catch( function (err) { console.log("ERR"); console.log(err); } ) console.log("DONE"); } });
constructor(currentItem: any) { super(currentItem); this.searchPageUrl = ko.observable(""); this.allDocumentsLabel = ko.observable(sprintf.sprintf(i18n.t("allDocumentsLabel"), _spPageContextInfo.webTitle.toLowerCase())); ko.bindingHandlers.getDocumentsSearchUrl = { init: () => { this.searchPageUrl(_spPageContextInfo.siteAbsoluteUrl + "/Pages/" + i18n.t("documentsSearchPageUrl")); }, }; }