mirror of
https://github.com/trympet/nextcloud-artifacts-action.git
synced 2025-04-24 20:16:08 +02:00
add dist
This commit is contained in:
parent
b0bfe891cd
commit
22aca2a29a
1
.gitignore
vendored
1
.gitignore
vendored
@ -80,7 +80,6 @@ typings/
|
||||
|
||||
# Nuxt.js build / generate output
|
||||
.nuxt
|
||||
dist
|
||||
|
||||
# Gatsby files
|
||||
.cache/
|
||||
|
151
dist/FileFinder.js
vendored
Normal file
151
dist/FileFinder.js
vendored
Normal file
@ -0,0 +1,151 @@
|
||||
"use strict";
|
||||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
||||
}) : (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
o[k2] = m[k];
|
||||
}));
|
||||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
||||
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
||||
}) : function(o, v) {
|
||||
o["default"] = v;
|
||||
});
|
||||
var __importStar = (this && this.__importStar) || function (mod) {
|
||||
if (mod && mod.__esModule) return mod;
|
||||
var result = {};
|
||||
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
||||
__setModuleDefault(result, mod);
|
||||
return result;
|
||||
};
|
||||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
||||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
||||
return new (P || (P = Promise))(function (resolve, reject) {
|
||||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
||||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
||||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
||||
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||
});
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.FileFinder = void 0;
|
||||
const glob = __importStar(require("@actions/glob"));
|
||||
const fs_1 = require("fs");
|
||||
const core_1 = require("@actions/core");
|
||||
const path = __importStar(require("path"));
|
||||
const util_1 = require("util");
|
||||
const stats = util_1.promisify(fs_1.stat);
|
||||
class FileFinder {
|
||||
constructor(searchPath, globOptions) {
|
||||
this.searchPath = searchPath;
|
||||
this.globOptions = globOptions || FileFinder.DefaultGlobOptions;
|
||||
}
|
||||
findFiles() {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
const searchResults = [];
|
||||
const globber = yield glob.create(this.searchPath, this.globOptions);
|
||||
const rawSearchResults = yield globber.glob();
|
||||
/*
|
||||
Files are saved with case insensitivity. Uploading both a.txt and A.txt will files to be overwritten
|
||||
Detect any files that could be overwritten for user awareness
|
||||
*/
|
||||
const set = new Set();
|
||||
/*
|
||||
Directories will be rejected if attempted to be uploaded. This includes just empty
|
||||
directories so filter any directories out from the raw search results
|
||||
*/
|
||||
for (const searchResult of rawSearchResults) {
|
||||
const fileStats = yield stats(searchResult);
|
||||
// isDirectory() returns false for symlinks if using fs.lstat(), make sure to use fs.stat() instead
|
||||
if (!fileStats.isDirectory()) {
|
||||
core_1.debug(`File:${searchResult} was found using the provided searchPath`);
|
||||
searchResults.push(searchResult);
|
||||
// detect any files that would be overwritten because of case insensitivity
|
||||
if (set.has(searchResult.toLowerCase())) {
|
||||
core_1.info(`Uploads are case insensitive: ${searchResult} was detected that it will be overwritten by another file with the same path`);
|
||||
}
|
||||
else {
|
||||
set.add(searchResult.toLowerCase());
|
||||
}
|
||||
}
|
||||
else {
|
||||
core_1.debug(`Removing ${searchResult} from rawSearchResults because it is a directory`);
|
||||
}
|
||||
}
|
||||
// Calculate the root directory for the artifact using the search paths that were utilized
|
||||
const searchPaths = globber.getSearchPaths();
|
||||
if (searchPaths.length > 1) {
|
||||
core_1.info(`Multiple search paths detected. Calculating the least common ancestor of all paths`);
|
||||
const lcaSearchPath = this.getMultiPathLCA(searchPaths);
|
||||
core_1.info(`The least common ancestor is ${lcaSearchPath}. This will be the root directory of the artifact`);
|
||||
return {
|
||||
filesToUpload: searchResults,
|
||||
rootDirectory: lcaSearchPath
|
||||
};
|
||||
}
|
||||
/*
|
||||
Special case for a single file artifact that is uploaded without a directory or wildcard pattern. The directory structure is
|
||||
not preserved and the root directory will be the single files parent directory
|
||||
*/
|
||||
if (searchResults.length === 1 && searchPaths[0] === searchResults[0]) {
|
||||
return {
|
||||
filesToUpload: searchResults,
|
||||
rootDirectory: path.dirname(searchResults[0])
|
||||
};
|
||||
}
|
||||
return {
|
||||
filesToUpload: searchResults,
|
||||
rootDirectory: searchPaths[0]
|
||||
};
|
||||
});
|
||||
}
|
||||
getMultiPathLCA(searchPaths) {
|
||||
if (searchPaths.length < 2) {
|
||||
throw new Error('At least two search paths must be provided');
|
||||
}
|
||||
const commonPaths = new Array();
|
||||
const splitPaths = new Array();
|
||||
let smallestPathLength = Number.MAX_SAFE_INTEGER;
|
||||
// split each of the search paths using the platform specific separator
|
||||
for (const searchPath of searchPaths) {
|
||||
core_1.debug(`Using search path ${searchPath}`);
|
||||
const splitSearchPath = path.normalize(searchPath).split(path.sep);
|
||||
// keep track of the smallest path length so that we don't accidentally later go out of bounds
|
||||
smallestPathLength = Math.min(smallestPathLength, splitSearchPath.length);
|
||||
splitPaths.push(splitSearchPath);
|
||||
}
|
||||
// on Unix-like file systems, the file separator exists at the beginning of the file path, make sure to preserve it
|
||||
if (searchPaths[0].startsWith(path.sep)) {
|
||||
commonPaths.push(path.sep);
|
||||
}
|
||||
let splitIndex = 0;
|
||||
// function to check if the paths are the same at a specific index
|
||||
function isPathTheSame() {
|
||||
const compare = splitPaths[0][splitIndex];
|
||||
for (let i = 1; i < splitPaths.length; i++) {
|
||||
if (compare !== splitPaths[i][splitIndex]) {
|
||||
// a non-common index has been reached
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
// loop over all the search paths until there is a non-common ancestor or we go out of bounds
|
||||
while (splitIndex < smallestPathLength) {
|
||||
if (!isPathTheSame()) {
|
||||
break;
|
||||
}
|
||||
// if all are the same, add to the end result & increment the index
|
||||
commonPaths.push(splitPaths[0][splitIndex]);
|
||||
splitIndex++;
|
||||
}
|
||||
return path.join(...commonPaths);
|
||||
}
|
||||
}
|
||||
exports.FileFinder = FileFinder;
|
||||
FileFinder.DefaultGlobOptions = {
|
||||
followSymbolicLinks: true,
|
||||
implicitDescendants: true,
|
||||
omitBrokenSymbolicLinks: true
|
||||
};
|
||||
//# sourceMappingURL=FileFinder.js.map
|
1
dist/FileFinder.js.map
vendored
Normal file
1
dist/FileFinder.js.map
vendored
Normal file
@ -0,0 +1 @@
|
||||
{"version":3,"file":"FileFinder.js","sourceRoot":"","sources":["../src/FileFinder.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,oDAAqC;AACrC,2BAAuB;AACvB,wCAAyC;AACzC,2CAA4B;AAC5B,+BAA8B;AAC9B,MAAM,KAAK,GAAG,gBAAS,CAAC,SAAI,CAAC,CAAA;AAE7B,MAAa,UAAU;IASnB,YAA2B,UAAkB,EAAE,WAA8B;QAAlD,eAAU,GAAV,UAAU,CAAQ;QACzC,IAAI,CAAC,WAAW,GAAG,WAAW,IAAI,UAAU,CAAC,kBAAkB,CAAC;IACpE,CAAC;IAEY,SAAS;;YAClB,MAAM,aAAa,GAAa,EAAE,CAAA;YAClC,MAAM,OAAO,GAAG,MAAM,IAAI,CAAC,MAAM,CAC7B,IAAI,CAAC,UAAU,EACf,IAAI,CAAC,WAAW,CACnB,CAAC;YAEF,MAAM,gBAAgB,GAAa,MAAM,OAAO,CAAC,IAAI,EAAE,CAAA;YAEvD;;;cAGE;YACF,MAAM,GAAG,GAAG,IAAI,GAAG,EAAU,CAAA;YAE7B;;;cAGE;YACF,KAAK,MAAM,YAAY,IAAI,gBAAgB,EAAE;gBACzC,MAA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C;QAED,6FAA6F;QAC7F,OAAO,UAAU,GAAG,kBAAkB,EAAE;YACtC,IAAI,CAAC,aAAa,EAAE,EAAE;gBACpB,MAAK;aACN;YACD,mEAAmE;YACnE,WAAW,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAA;YAC3C,UAAU,EAAE,CAAA;SACb;QACD,OAAO,IAAI,CAAC,IAAI,CAAC,GAAG,WAAW,CAAC,CAAA;IAClC,CAAC;;AAzIP,gCA0IC;AAzIkB,6BAAkB,GAAqB;IAClD,mBAAmB,EAAE,IAAI;IACzB,mBAAmB,EAAE,IAAI;IACzB,uBAAuB,EAAE,IAAI;CAChC,CAAC"}
|
38
dist/Inputs.js
vendored
Normal file
38
dist/Inputs.js
vendored
Normal file
@ -0,0 +1,38 @@
|
||||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.Inputs = void 0;
|
||||
const core_1 = __importDefault(require("@actions/core"));
|
||||
const NoFileOption_1 = require("./NoFileOption");
|
||||
class Inputs {
|
||||
static get ArtifactName() {
|
||||
return core_1.default.getInput("name");
|
||||
}
|
||||
static get ArtifactPath() {
|
||||
return core_1.default.getInput("path");
|
||||
}
|
||||
static get Retention() {
|
||||
return core_1.default.getInput("retention-days");
|
||||
}
|
||||
static get Endpoint() {
|
||||
return core_1.default.getInput("nextcloud-url");
|
||||
}
|
||||
static get Username() {
|
||||
return core_1.default.getInput("nextcloud-username");
|
||||
}
|
||||
static get Password() {
|
||||
return core_1.default.getInput("nextcloud-password");
|
||||
}
|
||||
static get NoFileBehvaior() {
|
||||
const notFoundAction = core_1.default.getInput("if-no-files-found");
|
||||
const noFileBehavior = NoFileOption_1.NoFileOption[notFoundAction];
|
||||
if (!noFileBehavior) {
|
||||
core_1.default.setFailed(`Unrecognized ${"ifNoFilesFound"} input. Provided: ${notFoundAction}. Available options: ${Object.keys(NoFileOption_1.NoFileOption)}`);
|
||||
}
|
||||
return noFileBehavior;
|
||||
}
|
||||
}
|
||||
exports.Inputs = Inputs;
|
||||
//# sourceMappingURL=Inputs.js.map
|
1
dist/Inputs.js.map
vendored
Normal file
1
dist/Inputs.js.map
vendored
Normal file
@ -0,0 +1 @@
|
||||
{"version":3,"file":"Inputs.js","sourceRoot":"","sources":["../src/Inputs.ts"],"names":[],"mappings":";;;;;;AAAA,yDAAiC;AACjC,iDAA8C;AAE9C,MAAa,MAAM;IACf,MAAM,KAAK,YAAY;QACnB,OAAO,cAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;IACjC,CAAC;IAED,MAAM,KAAK,YAAY;QACnB,OAAO,cAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;IACjC,CAAC;IAED,MAAM,KAAK,SAAS;QAChB,OAAO,cAAI,CAAC,QAAQ,CAAC,gBAAgB,CAAC,CAAC;IAC3C,CAAC;IAED,MAAM,KAAK,QAAQ;QACf,OAAO,cAAI,CAAC,QAAQ,CAAC,eAAe,CAAC,CAAC;IAC1C,CAAC;IAED,MAAM,KAAK,QAAQ;QACf,OAAO,cAAI,CAAC,QAAQ,CAAC,oBAAoB,CAAC,CAAC;IAC/C,CAAC;IAED,MAAM,KAAK,QAAQ;QACf,OAAO,cAAI,CAAC,QAAQ,CAAC,oBAAoB,CAAC,CAAC;IAC/C,CAAC;IAED,MAAM,KAAK,cAAc;QACrB,MAAM,cAAc,GAAG,cAAI,CAAC,QAAQ,CAAC,mBAAmB,CAAC,CAAC;QAC1D,MAAM,cAAc,GAAiB,2BAAY,CAAC,cAA2C,CAAC,CAAC;QAE/F,IAAI,CAAC,cAAc,EAAE;YACjB,cAAI,CAAC,SAAS,CACV,gBAAgB,gBAAgB,qBAAqB,cAAc,wBAAwB,MAAM,CAAC,IAAI,CAClG,2BAAY,CACf,EAAE,CACN,CAAC;SACL;QAED,OAAO,cAAc,CAAC;IAC1B,CAAC;CACJ;AAvCD,wBAuCC"}
|
73
dist/NextcloudArtifact.js
vendored
Normal file
73
dist/NextcloudArtifact.js
vendored
Normal file
@ -0,0 +1,73 @@
|
||||
"use strict";
|
||||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
||||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
||||
return new (P || (P = Promise))(function (resolve, reject) {
|
||||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
||||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
||||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
||||
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||
});
|
||||
};
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.NextcloudArtifact = void 0;
|
||||
const core_1 = __importDefault(require("@actions/core"));
|
||||
const FileFinder_1 = require("./FileFinder");
|
||||
const Inputs_1 = require("./Inputs");
|
||||
const NextcloudClient_1 = require("./nextcloud/NextcloudClient");
|
||||
const NoFileOption_1 = require("./NoFileOption");
|
||||
class NextcloudArtifact {
|
||||
constructor(name, path, errorBehavior) {
|
||||
this.name = name;
|
||||
this.path = path;
|
||||
this.errorBehavior = errorBehavior;
|
||||
}
|
||||
run() {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
const fileFinder = new FileFinder_1.FileFinder(this.path);
|
||||
const files = yield fileFinder.findFiles();
|
||||
if (files.filesToUpload.length > 0) {
|
||||
yield this.uploadFiles(files);
|
||||
}
|
||||
else {
|
||||
this.logNoFilesFound();
|
||||
}
|
||||
});
|
||||
}
|
||||
uploadFiles(files) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
this.logUpload(files.filesToUpload.length, files.rootDirectory);
|
||||
const client = new NextcloudClient_1.NextcloudClient(Inputs_1.Inputs.endpoint, this.name, files.rootDirectory);
|
||||
yield client.uploadFiles(files.filesToUpload);
|
||||
});
|
||||
}
|
||||
logUpload(fileCount, rootDirectory) {
|
||||
const s = fileCount === 1 ? '' : 's';
|
||||
core_1.default.info(`With the provided path, there will be ${fileCount} file${s} uploaded`);
|
||||
core_1.default.debug(`Root artifact directory is ${rootDirectory}`);
|
||||
if (fileCount > 10000) {
|
||||
core_1.default.warning(`There are over 10,000 files in this artifact, consider create an archive before upload to improve the upload performance.`);
|
||||
}
|
||||
}
|
||||
logNoFilesFound() {
|
||||
const errorMessage = `No files were found with the provided path: ${this.path}. No artifacts will be uploaded.`;
|
||||
switch (this.errorBehavior) {
|
||||
case NoFileOption_1.NoFileOption.warn: {
|
||||
core_1.default.warning(errorMessage);
|
||||
break;
|
||||
}
|
||||
case NoFileOption_1.NoFileOption.error: {
|
||||
core_1.default.setFailed(errorMessage);
|
||||
break;
|
||||
}
|
||||
case NoFileOption_1.NoFileOption.ignore: {
|
||||
core_1.default.info(errorMessage);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
exports.NextcloudArtifact = NextcloudArtifact;
|
||||
//# sourceMappingURL=NextcloudArtifact.js.map
|
1
dist/NextcloudArtifact.js.map
vendored
Normal file
1
dist/NextcloudArtifact.js.map
vendored
Normal file
@ -0,0 +1 @@
|
||||
{"version":3,"file":"NextcloudArtifact.js","sourceRoot":"","sources":["../src/NextcloudArtifact.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,yDAAiC;AACjC,6CAA0C;AAC1C,qCAAkC;AAClC,iEAA8D;AAC9D,iDAA8C;AAE9C,MAAa,iBAAiB;IAC1B,YACY,IAAY,EACZ,IAAY,EACZ,aAA2B;QAF3B,SAAI,GAAJ,IAAI,CAAQ;QACZ,SAAI,GAAJ,IAAI,CAAQ;QACZ,kBAAa,GAAb,aAAa,CAAc;IAAI,CAAC;IAE/B,GAAG;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CAAC;gBAC3B,MAAM;aACT;YACD,KAAK,2BAAY,CAAC,KAAK,CAAC,CAAC;gBACrB,cAAI,CAAC,SAAS,CAAC,YAAY,CAAC,CAAC;gBAC7B,MAAM;aACT;YACD,KAAK,2BAAY,CAAC,MAAM,CAAC,CAAC;gBACtB,cAAI,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;gBACxB,MAAM;aACT;SACJ;IACL,CAAC;CACJ;AAzDD,8CAyDC"}
|
19
dist/NoFileOption.js
vendored
Normal file
19
dist/NoFileOption.js
vendored
Normal file
@ -0,0 +1,19 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.NoFileOption = void 0;
|
||||
var NoFileOption;
|
||||
(function (NoFileOption) {
|
||||
/**
|
||||
* Default. Output a warning but do not fail the action
|
||||
*/
|
||||
NoFileOption["warn"] = "warn";
|
||||
/**
|
||||
* Fail the action with an error message
|
||||
*/
|
||||
NoFileOption["error"] = "error";
|
||||
/**
|
||||
* Do not output any warnings or errors, the action does not fail
|
||||
*/
|
||||
NoFileOption["ignore"] = "ignore";
|
||||
})(NoFileOption = exports.NoFileOption || (exports.NoFileOption = {}));
|
||||
//# sourceMappingURL=NoFileOption.js.map
|
1
dist/NoFileOption.js.map
vendored
Normal file
1
dist/NoFileOption.js.map
vendored
Normal file
@ -0,0 +1 @@
|
||||
{"version":3,"file":"NoFileOption.js","sourceRoot":"","sources":["../src/NoFileOption.ts"],"names":[],"mappings":";;;AAAA,IAAY,YAeT;AAfH,WAAY,YAAY;IACpB;;OAEG;IACH,6BAAa,CAAA;IAEb;;OAEG;IACH,+BAAe,CAAA;IAEf;;OAEG;IACH,iCAAiB,CAAA;AACnB,CAAC,EAfS,YAAY,GAAZ,oBAAY,KAAZ,oBAAY,QAerB"}
|
7
dist/index.js
vendored
Normal file
7
dist/index.js
vendored
Normal file
@ -0,0 +1,7 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const Inputs_1 = require("./Inputs");
|
||||
const NextcloudArtifact_1 = require("./nextcloud/NextcloudArtifact");
|
||||
var artifact = new NextcloudArtifact_1.NextcloudArtifact(Inputs_1.Inputs.ArtifactName, Inputs_1.Inputs.ArtifactPath, Inputs_1.Inputs.NoFileBehvaior);
|
||||
artifact.run();
|
||||
//# sourceMappingURL=index.js.map
|
1
dist/index.js.map
vendored
Normal file
1
dist/index.js.map
vendored
Normal file
@ -0,0 +1 @@
|
||||
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;AAAA,qCAAkC;AAClC,qEAAkE;AAElE,IAAI,QAAQ,GAAG,IAAI,qCAAiB,CAAC,eAAM,CAAC,YAAY,EAAE,eAAM,CAAC,YAAY,EAAE,eAAM,CAAC,cAAc,CAAC,CAAC;AACtG,QAAQ,CAAC,GAAG,EAAE,CAAC"}
|
51
dist/input-helper.js
vendored
Normal file
51
dist/input-helper.js
vendored
Normal file
@ -0,0 +1,51 @@
|
||||
"use strict";
|
||||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
||||
}) : (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
o[k2] = m[k];
|
||||
}));
|
||||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
||||
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
||||
}) : function(o, v) {
|
||||
o["default"] = v;
|
||||
});
|
||||
var __importStar = (this && this.__importStar) || function (mod) {
|
||||
if (mod && mod.__esModule) return mod;
|
||||
var result = {};
|
||||
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
||||
__setModuleDefault(result, mod);
|
||||
return result;
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.getInputs = void 0;
|
||||
const core = __importStar(require("@actions/core"));
|
||||
const constants_1 = require("./constants");
|
||||
/**
|
||||
* Helper to get all the inputs for the action
|
||||
*/
|
||||
function getInputs() {
|
||||
const name = core.getInput(constants_1.Inputs.Name);
|
||||
const path = core.getInput(constants_1.Inputs.Path, { required: true });
|
||||
const ifNoFilesFound = core.getInput(constants_1.Inputs.IfNoFilesFound);
|
||||
const noFileBehavior = constants_1.NoFileOptions[ifNoFilesFound];
|
||||
if (!noFileBehavior) {
|
||||
core.setFailed(`Unrecognized ${constants_1.Inputs.IfNoFilesFound} input. Provided: ${ifNoFilesFound}. Available options: ${Object.keys(constants_1.NoFileOptions)}`);
|
||||
}
|
||||
const inputs = {
|
||||
artifactName: name,
|
||||
searchPath: path,
|
||||
ifNoFilesFound: noFileBehavior
|
||||
};
|
||||
const retentionDaysStr = core.getInput(constants_1.Inputs.RetentionDays);
|
||||
if (retentionDaysStr) {
|
||||
inputs.retentionDays = parseInt(retentionDaysStr);
|
||||
if (isNaN(inputs.retentionDays)) {
|
||||
core.setFailed('Invalid retention-days');
|
||||
}
|
||||
}
|
||||
return inputs;
|
||||
}
|
||||
exports.getInputs = getInputs;
|
||||
//# sourceMappingURL=input-helper.js.map
|
1
dist/input-helper.js.map
vendored
Normal file
1
dist/input-helper.js.map
vendored
Normal file
@ -0,0 +1 @@
|
||||
{"version":3,"file":"input-helper.js","sourceRoot":"","sources":["../src/input-helper.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAAA,oDAAqC;AACrC,2CAAiD;AAGjD;;GAEG;AACH,SAAgB,SAAS;IACvB,MAAM,IAAI,GAAG,IAAI,CAAC,QAAQ,CAAC,kBAAM,CAAC,IAAI,CAAC,CAAA;IACvC,MAAM,IAAI,GAAG,IAAI,CAAC,QAAQ,CAAC,kBAAM,CAAC,IAAI,EAAE,EAAC,QAAQ,EAAE,IAAI,EAAC,CAAC,CAAA;IAEzD,MAAM,cAAc,GAAG,IAAI,CAAC,QAAQ,CAAC,kBAAM,CAAC,cAAc,CAAC,CAAA;IAC3D,MAAM,cAAc,GAAkB,yBAAa,CAAC,cAAc,CAAC,CAAA;IAEnE,IAAI,CAAC,cAAc,EAAE;QACnB,IAAI,CAAC,SAAS,CACZ,gBACE,kBAAM,CAAC,cACT,qBAAqB,cAAc,wBAAwB,MAAM,CAAC,IAAI,CACpE,yBAAa,CACd,EAAE,CACJ,CAAA;KACF;IAED,MAAM,MAAM,GAAG;QACb,YAAY,EAAE,IAAI;QAClB,UAAU,EAAE,IAAI;QAChB,cAAc,EAAE,cAAc;KACf,CAAA;IAEjB,MAAM,gBAAgB,GAAG,IAAI,CAAC,QAAQ,CAAC,kBAAM,CAAC,aAAa,CAAC,CAAA;IAC5D,IAAI,gBAAgB,EAAE;QACpB,MAAM,CAAC,aAAa,GAAG,QAAQ,CAAC,gBAAgB,CAAC,CAAA;QACjD,IAAI,KAAK,CAAC,MAAM,CAAC,aAAa,CAAC,EAAE;YAC/B,IAAI,CAAC,SAAS,CAAC,wBAAwB,CAAC,CAAA;SACzC;KACF;IAED,OAAO,MAAM,CAAA;AACf,CAAC;AAhCD,8BAgCC"}
|
73
dist/nextcloud/NextcloudArtifact.js
vendored
Normal file
73
dist/nextcloud/NextcloudArtifact.js
vendored
Normal file
@ -0,0 +1,73 @@
|
||||
"use strict";
|
||||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
||||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
||||
return new (P || (P = Promise))(function (resolve, reject) {
|
||||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
||||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
||||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
||||
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||
});
|
||||
};
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.NextcloudArtifact = void 0;
|
||||
const core_1 = __importDefault(require("@actions/core"));
|
||||
const FileFinder_1 = require("../FileFinder");
|
||||
const Inputs_1 = require("../Inputs");
|
||||
const NextcloudClient_1 = require("./NextcloudClient");
|
||||
const NoFileOption_1 = require("../NoFileOption");
|
||||
class NextcloudArtifact {
|
||||
constructor(name, path, errorBehavior) {
|
||||
this.name = name;
|
||||
this.path = path;
|
||||
this.errorBehavior = errorBehavior;
|
||||
}
|
||||
run() {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
const fileFinder = new FileFinder_1.FileFinder(this.path);
|
||||
const files = yield fileFinder.findFiles();
|
||||
if (files.filesToUpload.length > 0) {
|
||||
yield this.uploadFiles(files);
|
||||
}
|
||||
else {
|
||||
this.logNoFilesFound();
|
||||
}
|
||||
});
|
||||
}
|
||||
uploadFiles(files) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
this.logUpload(files.filesToUpload.length, files.rootDirectory);
|
||||
const client = new NextcloudClient_1.NextcloudClient(Inputs_1.Inputs.Endpoint, this.name, files.rootDirectory);
|
||||
yield client.uploadFiles(files.filesToUpload);
|
||||
});
|
||||
}
|
||||
logUpload(fileCount, rootDirectory) {
|
||||
const s = fileCount === 1 ? '' : 's';
|
||||
core_1.default.info(`With the provided path, there will be ${fileCount} file${s} uploaded`);
|
||||
core_1.default.debug(`Root artifact directory is ${rootDirectory}`);
|
||||
if (fileCount > 10000) {
|
||||
core_1.default.warning(`There are over 10,000 files in this artifact, consider create an archive before upload to improve the upload performance.`);
|
||||
}
|
||||
}
|
||||
logNoFilesFound() {
|
||||
const errorMessage = `No files were found with the provided path: ${this.path}. No artifacts will be uploaded.`;
|
||||
switch (this.errorBehavior) {
|
||||
case NoFileOption_1.NoFileOption.warn: {
|
||||
core_1.default.warning(errorMessage);
|
||||
break;
|
||||
}
|
||||
case NoFileOption_1.NoFileOption.error: {
|
||||
core_1.default.setFailed(errorMessage);
|
||||
break;
|
||||
}
|
||||
case NoFileOption_1.NoFileOption.ignore: {
|
||||
core_1.default.info(errorMessage);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
exports.NextcloudArtifact = NextcloudArtifact;
|
||||
//# sourceMappingURL=NextcloudArtifact.js.map
|
1
dist/nextcloud/NextcloudArtifact.js.map
vendored
Normal file
1
dist/nextcloud/NextcloudArtifact.js.map
vendored
Normal file
@ -0,0 +1 @@
|
||||
{"version":3,"file":"NextcloudArtifact.js","sourceRoot":"","sources":["../../src/nextcloud/NextcloudArtifact.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,yDAAiC;AACjC,8CAA2C;AAC3C,sCAAmC;AACnC,uDAAoD;AACpD,kDAA+C;AAE/C,MAAa,iBAAiB;IAC1B,YACY,IAAY,EACZ,IAAY,EACZ,aAA2B;QAF3B,SAAI,GAAJ,IAAI,CAAQ;QACZ,SAAI,GAAJ,IAAI,CAAQ;QACZ,kBAAa,GAAb,aAAa,CAAc;IAAI,CAAC;IAE/B,GAAG;;YACZ,MAAM,UAAU,GAAG,IAAI,uBAAU,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;YAC7C,MAAM,KAAK,GAAG,MAAM,UAAU,CAAC,SAAS,EAAE,CAAC;YAE3C,IAAI,KAAK,CAAC,aAAa,CAAC,MAAM,GAAG,CAAC,EAAE;gBAChC,MAAM,IAAI,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC;aACjC;iBACI;gBACD,IAAI,CAAC,eAAe,EAAE,CAAC;aAC1B;QACL,CAAC;KAAA;IAEa,WAAW,CAAC,KAA0D;;YAChF,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,aAAa,CAAC,MAAM,EAAE,KAAK,CAAC,aAAa,CAAC,CAAC;YAEhE,MAAM,MAAM,GAAG,IAAI,iCAAe,CAAC,eAAM,CAAC,QAAQ,EAAE,IAAI,CAAC,IAAI,EAAE,KAAK,CAAC,aAAa,CAAC,CAAC;YAEpF,MAAM,MAAM,CAAC,WAAW,CAAC,KAAK,CAAC,aAAa,CAAC,CAAC;QAClD,CAAC;KAAA;IAEO,SAAS,CAAC,SAAiB,EAAE,aAAqB;QACtD,MAAM,CAAC,GAAG,SAAS,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC;QACrC,cAAI,CAAC,IAAI,CACL,yCAAyC,SAAS,QAAQ,CAAC,WAAW,CACzE,CAAC;QACF,cAAI,CAAC,KAAK,CAAC,8BAA8B,aAAa,EAAE,CAAC,CAAC;QAE1D,IAAI,SAAS,GAAG,KAAK,EAAE;YACnB,cAAI,CAAC,OAAO,CACR,2HAA2H,CAC9H,CAAC;SACL;IACL,CAAC;IAEO,eAAe;QACnB,MAAM,YAAY,GAAG,+CAA+C,IAAI,CAAC,IAAI,kCAAkC,CAAC;QAChH,QAAQ,IAAI,CAAC,aAAa,EAAE;YACxB,KAAK,2BAAY,CAAC,IAAI,CAAC,CAAC;gBACpB,cAAI,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC;gBAC3B,MAAM;aACT;YACD,KAAK,2BAAY,CAAC,KAAK,CAAC,CAAC;gBACrB,cAAI,CAAC,SAAS,CAAC,YAAY,CAAC,CAAC;gBAC7B,MAAM;aACT;YACD,KAAK,2BAAY,CAAC,MAAM,CAAC,CAAC;gBACtB,cAAI,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;gBACxB,MAAM;aACT;SACJ;IACL,CAAC;CACJ;AAzDD,8CAyDC"}
|
183
dist/nextcloud/NextcloudClient.js
vendored
Normal file
183
dist/nextcloud/NextcloudClient.js
vendored
Normal file
@ -0,0 +1,183 @@
|
||||
"use strict";
|
||||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
||||
}) : (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
o[k2] = m[k];
|
||||
}));
|
||||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
||||
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
||||
}) : function(o, v) {
|
||||
o["default"] = v;
|
||||
});
|
||||
var __importStar = (this && this.__importStar) || function (mod) {
|
||||
if (mod && mod.__esModule) return mod;
|
||||
var result = {};
|
||||
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
||||
__setModuleDefault(result, mod);
|
||||
return result;
|
||||
};
|
||||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
||||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
||||
return new (P || (P = Promise))(function (resolve, reject) {
|
||||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
||||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
||||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
||||
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||
});
|
||||
};
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.NextcloudClient = void 0;
|
||||
const fsSync = __importStar(require("fs"));
|
||||
const fs = __importStar(require("fs/promises"));
|
||||
const path = __importStar(require("path"));
|
||||
const core_1 = __importDefault(require("@actions/core"));
|
||||
const os = __importStar(require("os"));
|
||||
const crypto_1 = require("crypto");
|
||||
const archiver = __importStar(require("archiver"));
|
||||
const node_fetch_1 = __importDefault(require("node-fetch"));
|
||||
const Inputs_1 = require("../Inputs");
|
||||
const btoa_1 = __importDefault(require("btoa"));
|
||||
class NextcloudClient {
|
||||
constructor(endpoint, artifact, rootDirectory) {
|
||||
this.endpoint = endpoint;
|
||||
this.artifact = artifact;
|
||||
this.rootDirectory = rootDirectory;
|
||||
this.guid = crypto_1.randomUUID();
|
||||
this.headers = { 'Authorization': 'Basic ' + btoa_1.default(`${Inputs_1.Inputs.Username}:${Inputs_1.Inputs.Password}`) };
|
||||
}
|
||||
uploadFiles(files) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
const spec = this.uploadSpec(files);
|
||||
var zip = yield this.zipFiles(spec);
|
||||
const path = yield this.upload(zip);
|
||||
yield this.shareFile(path);
|
||||
});
|
||||
}
|
||||
uploadSpec(files) {
|
||||
const specifications = [];
|
||||
if (!fsSync.existsSync(this.rootDirectory)) {
|
||||
throw new Error(`this.rootDirectory ${this.rootDirectory} does not exist`);
|
||||
}
|
||||
if (!fsSync.lstatSync(this.rootDirectory).isDirectory()) {
|
||||
throw new Error(`this.rootDirectory ${this.rootDirectory} is not a valid directory`);
|
||||
}
|
||||
// Normalize and resolve, this allows for either absolute or relative paths to be used
|
||||
let root = path.normalize(this.rootDirectory);
|
||||
root = path.resolve(root);
|
||||
/*
|
||||
Example to demonstrate behavior
|
||||
|
||||
Input:
|
||||
artifactName: my-artifact
|
||||
rootDirectory: '/home/user/files/plz-upload'
|
||||
artifactFiles: [
|
||||
'/home/user/files/plz-upload/file1.txt',
|
||||
'/home/user/files/plz-upload/file2.txt',
|
||||
'/home/user/files/plz-upload/dir/file3.txt'
|
||||
]
|
||||
|
||||
Output:
|
||||
specifications: [
|
||||
['/home/user/files/plz-upload/file1.txt', 'my-artifact/file1.txt'],
|
||||
['/home/user/files/plz-upload/file1.txt', 'my-artifact/file2.txt'],
|
||||
['/home/user/files/plz-upload/file1.txt', 'my-artifact/dir/file3.txt']
|
||||
]
|
||||
*/
|
||||
for (let file of files) {
|
||||
if (!fsSync.existsSync(file)) {
|
||||
throw new Error(`File ${file} does not exist`);
|
||||
}
|
||||
if (!fsSync.lstatSync(file).isDirectory()) {
|
||||
// Normalize and resolve, this allows for either absolute or relative paths to be used
|
||||
file = path.normalize(file);
|
||||
file = path.resolve(file);
|
||||
if (!file.startsWith(root)) {
|
||||
throw new Error(`The rootDirectory: ${root} is not a parent directory of the file: ${file}`);
|
||||
}
|
||||
// Check for forbidden characters in file paths that will be rejected during upload
|
||||
const uploadPath = file.replace(root, '');
|
||||
/*
|
||||
uploadFilePath denotes where the file will be uploaded in the file container on the server. During a run, if multiple artifacts are uploaded, they will all
|
||||
be saved in the same container. The artifact name is used as the root directory in the container to separate and distinguish uploaded artifacts
|
||||
|
||||
path.join handles all the following cases and would return 'artifact-name/file-to-upload.txt
|
||||
join('artifact-name/', 'file-to-upload.txt')
|
||||
join('artifact-name/', '/file-to-upload.txt')
|
||||
join('artifact-name', 'file-to-upload.txt')
|
||||
join('artifact-name', '/file-to-upload.txt')
|
||||
*/
|
||||
specifications.push({
|
||||
absolutePath: file,
|
||||
uploadPath: path.join(this.artifact, uploadPath)
|
||||
});
|
||||
}
|
||||
else {
|
||||
// Directories are rejected by the server during upload
|
||||
core_1.default.debug(`Removing ${file} from rawSearchResults because it is a directory`);
|
||||
}
|
||||
}
|
||||
return specifications;
|
||||
}
|
||||
zipFiles(specs) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
const tempArtifactDir = path.join(os.tmpdir(), this.guid);
|
||||
const artifactPath = path.join(tempArtifactDir, `artifact-${this.artifact}`);
|
||||
yield fs.mkdir(artifactPath, { recursive: true });
|
||||
for (let spec of specs) {
|
||||
yield fs.copyFile(spec.absolutePath, path.join(artifactPath, spec.uploadPath));
|
||||
}
|
||||
const archivePath = path.join(artifactPath, `${this.artifact}.zip`);
|
||||
yield this.zip(path.join(artifactPath, this.artifact), archivePath);
|
||||
return archivePath;
|
||||
});
|
||||
}
|
||||
zip(dirpath, destpath) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
const archive = archiver.create('zip', { zlib: { level: 9 } });
|
||||
const stream = fsSync.createWriteStream(destpath);
|
||||
archive.directory(dirpath, false)
|
||||
.on('error', e => Promise.reject())
|
||||
.on('close', () => Promise.resolve())
|
||||
.pipe(stream);
|
||||
return archive.finalize();
|
||||
});
|
||||
}
|
||||
upload(file) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
const filePath = `/artifacts/${this.guid}/${this.artifact}`;
|
||||
const url = this.endpoint + `/remote.php/dav/files/${Inputs_1.Inputs.Username}` + filePath;
|
||||
const stream = fsSync.createReadStream(file);
|
||||
const res = yield node_fetch_1.default(url, {
|
||||
method: 'PUT',
|
||||
body: stream,
|
||||
headers: this.headers
|
||||
});
|
||||
core_1.default.debug(yield res.json());
|
||||
return filePath;
|
||||
});
|
||||
}
|
||||
shareFile(nextcloudPath) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
const url = this.endpoint + `/ocs/v2.php/apps/files_sharing/api/v1/shares`;
|
||||
const body = {
|
||||
path: nextcloudPath,
|
||||
shareType: 3,
|
||||
publicUpload: "false",
|
||||
permissions: 1,
|
||||
};
|
||||
const res = yield node_fetch_1.default(url, {
|
||||
method: 'PUT',
|
||||
headers: this.headers,
|
||||
body: JSON.stringify(body),
|
||||
});
|
||||
core_1.default.debug(yield res.json());
|
||||
});
|
||||
}
|
||||
}
|
||||
exports.NextcloudClient = NextcloudClient;
|
||||
//# sourceMappingURL=NextcloudClient.js.map
|
1
dist/nextcloud/NextcloudClient.js.map
vendored
Normal file
1
dist/nextcloud/NextcloudClient.js.map
vendored
Normal file
@ -0,0 +1 @@
|
||||
{"version":3,"file":"NextcloudClient.js","sourceRoot":"","sources":["../../src/nextcloud/NextcloudClient.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,2CAA4B;AAC5B,gDAAiC;AACjC,2CAA4B;AAC5B,yDAAiC;AACjC,uCAAyB;AACzB,mCAAoC;AACpC,mDAAqC;AAErC,4DAAgD;AAChD,sCAAmC;AACnC,gDAAwB;AAOxB,MAAa,eAAe;IAIxB,YACY,QAAgB,EAChB,Q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,EAAE,GAAG,QAAQ,CAAC;YAClF,MAAM,MAAM,GAAG,MAAM,CAAC,gBAAgB,CAAC,IAAI,CAAC,CAAC;YAC7C,MAAM,GAAG,GAAG,MAAM,oBAAK,CAAC,GAAG,EAAE;gBACzB,MAAM,EAAE,KAAK;gBACb,IAAI,EAAE,MAAM;gBACZ,OAAO,EAAE,IAAI,CAAC,OAAO;aACxB,CAAC,CAAC;YACH,cAAI,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,IAAI,EAAE,CAAC,CAAA;YAE5B,OAAO,QAAQ,CAAC;QACpB,CAAC;KAAA;IAEa,SAAS,CAAC,aAAqB;;YACzC,MAAM,GAAG,GAAG,IAAI,CAAC,QAAQ,GAAG,8CAA8C,CAAC;YAC3E,MAAM,IAAI,GAAG;gBACT,IAAI,EAAE,aAAa;gBACnB,SAAS,EAAE,CAAC;gBACZ,YAAY,EAAE,OAAO;gBACrB,WAAW,EAAE,CAAC;aACjB,CAAC;YAEF,MAAM,GAAG,GAAG,MAAM,oBAAK,CAAC,GAAG,EAAE;gBACzB,MAAM,EAAE,KAAK;gBACb,OAAO,EAAE,IAAI,CAAC,OAAO;gBACrB,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC;aAC7B,CAAC,CAAC;YAEH,cAAI,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,IAAI,EAAE,CAAC,CAAA;QAChC,CAAC;KAAA;CACJ;AA9ID,0CA8IC"}
|
3
dist/upload-inputs.js
vendored
Normal file
3
dist/upload-inputs.js
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
//# sourceMappingURL=upload-inputs.js.map
|
1
dist/upload-inputs.js.map
vendored
Normal file
1
dist/upload-inputs.js.map
vendored
Normal file
@ -0,0 +1 @@
|
||||
{"version":3,"file":"upload-inputs.js","sourceRoot":"","sources":["../src/upload-inputs.ts"],"names":[],"mappings":""}
|
Loading…
x
Reference in New Issue
Block a user