This commit is contained in:
Oscar Plaisant
2024-05-14 10:51:40 +02:00
parent f71d6b0503
commit 66c143b7b3
164 changed files with 25026 additions and 13829 deletions

View File

@@ -658,23 +658,80 @@ var import_obsidian3 = require("obsidian");
// src/features/githubUtils.ts
var import_obsidian = require("obsidian");
var GITHUB_RAW_USERCONTENT_PATH = "https://raw.githubusercontent.com/";
var grabReleaseFileFromRepository = async (repository, version, fileName, debugLogging = true) => {
const URL = `https://github.com/${repository}/releases/download/${version}/${fileName}`;
var isPrivateRepo = async (repository, debugLogging = true, personalAccessToken = "") => {
const URL2 = `https://api.github.com/repos/${repository}`;
try {
const download = await (0, import_obsidian.request)({ url: URL });
return download === "Not Found" || download === `{"error":"Not Found"}` ? null : download;
const response = await (0, import_obsidian.request)({
url: URL2,
headers: personalAccessToken ? {
Authorization: `Token ${personalAccessToken}`
} : {}
});
const data = await JSON.parse(response);
return data.private;
} catch (e) {
if (debugLogging)
console.log("error in isPrivateRepo", URL2, e);
return false;
}
};
var grabReleaseFileFromRepository = async (repository, version, fileName, debugLogging = true, personalAccessToken = "") => {
try {
const isPrivate = await isPrivateRepo(repository, debugLogging, personalAccessToken);
if (isPrivate) {
const URL2 = `https://api.github.com/repos/${repository}/releases`;
const response = await (0, import_obsidian.request)({
url: URL2,
headers: {
Authorization: `Token ${personalAccessToken}`
}
});
const data = await JSON.parse(response);
const release = data.find((release2) => release2.tag_name === version);
if (!release) {
return null;
}
const asset = release.assets.find(
(asset2) => asset2.name === fileName
);
if (!asset) {
return null;
}
const download = await (0, import_obsidian.request)({
url: asset.url,
headers: {
Authorization: `Token ${personalAccessToken}`,
Accept: "application/octet-stream"
}
});
return download === "Not Found" || download === `{"error":"Not Found"}` ? null : download;
} else {
const URL2 = `https://github.com/${repository}/releases/download/${version}/${fileName}`;
const download = await (0, import_obsidian.request)({
url: URL2,
headers: personalAccessToken ? {
Authorization: `Token ${personalAccessToken}`
} : {}
});
return download === "Not Found" || download === `{"error":"Not Found"}` ? null : download;
}
} catch (error) {
if (debugLogging)
console.log("error in grabReleaseFileFromRepository", URL, error);
return null;
}
};
var grabManifestJsonFromRepository = async (repositoryPath, rootManifest = true, debugLogging = true) => {
var grabManifestJsonFromRepository = async (repositoryPath, rootManifest = true, debugLogging = true, personalAccessToken = "") => {
const manifestJsonPath = GITHUB_RAW_USERCONTENT_PATH + repositoryPath + (rootManifest ? "/HEAD/manifest.json" : "/HEAD/manifest-beta.json");
if (debugLogging)
console.log("grabManifestJsonFromRepository manifestJsonPath", manifestJsonPath);
try {
const response = await (0, import_obsidian.request)({ url: manifestJsonPath });
const response = await (0, import_obsidian.request)({
url: manifestJsonPath,
headers: personalAccessToken ? {
Authorization: `Token ${personalAccessToken}`
} : {}
});
if (debugLogging)
console.log("grabManifestJsonFromRepository response", response);
return response === "404: Not Found" ? null : await JSON.parse(response);
@@ -783,7 +840,8 @@ var DEFAULT_SETTINGS = {
loggingPath: "BRAT-log",
loggingVerboseEnabled: false,
debuggingMode: false,
notificationsEnabled: true
notificationsEnabled: true,
personalAccessToken: ""
};
function addBetaPluginToList(plugin, repositoryPath, specifyVersion = "") {
let save = false;
@@ -1265,6 +1323,15 @@ var BratSettingsTab = class extends import_obsidian5.PluginSettingTab {
await this.plugin.saveSettings();
});
});
new import_obsidian5.Setting(containerEl).setName("Personal Access Token").setDesc(
"If you need to access private repositories, enter the personal access token here."
).addText((text) => {
var _a;
text.setPlaceholder("Enter your personal access token").setValue((_a = this.plugin.settings.personalAccessToken) != null ? _a : "").onChange(async (value) => {
this.plugin.settings.personalAccessToken = value;
await this.plugin.saveSettings();
});
});
}
};
@@ -1433,16 +1500,24 @@ var BetaPlugins = class {
const manifestJson = await grabManifestJsonFromRepository(
repositoryPath,
!getBetaManifest,
this.plugin.settings.debuggingMode
this.plugin.settings.debuggingMode,
this.plugin.settings.personalAccessToken
);
if (!manifestJson) {
if (reportIssues)
if (reportIssues) {
toastMessage(
this.plugin,
`${repositoryPath}
This does not seem to be an obsidian plugin, as there is no manifest.json file.`,
noticeTimeout
);
console.error(
"BRAT: validateRepository",
repositoryPath,
getBetaManifest,
reportIssues
);
}
return null;
}
if (!("id" in manifestJson)) {
@@ -1480,24 +1555,28 @@ The version attribute for the release is missing from the manifest file`,
async getAllReleaseFiles(repositoryPath, manifest, getManifest, specifyVersion = "") {
const version = specifyVersion === "" ? manifest.version : specifyVersion;
const reallyGetManifestOrNot = getManifest || specifyVersion !== "";
console.log({ reallyGetManifestOrNot, version });
return {
mainJs: await grabReleaseFileFromRepository(
repositoryPath,
version,
"main.js",
this.plugin.settings.debuggingMode
this.plugin.settings.debuggingMode,
this.plugin.settings.personalAccessToken
),
manifest: reallyGetManifestOrNot ? await grabReleaseFileFromRepository(
repositoryPath,
version,
"manifest.json",
this.plugin.settings.debuggingMode
this.plugin.settings.debuggingMode,
this.plugin.settings.personalAccessToken
) : "",
styles: await grabReleaseFileFromRepository(
repositoryPath,
version,
"styles.css",
this.plugin.settings.debuggingMode
this.plugin.settings.debuggingMode,
this.plugin.settings.personalAccessToken
)
};
}
@@ -1587,6 +1666,7 @@ You will need to update your Obsidian to use this plugin or contact the plugin d
usingBetaManifest,
specifyVersion
);
console.log("rFiles", rFiles);
if (usingBetaManifest || rFiles.manifest === "")
rFiles.manifest = JSON.stringify(primaryManifest);
if (this.plugin.settings.debuggingMode)

View File

@@ -1,15 +1,15 @@
{
"id": "obsidian42-brat",
"name": "BRAT",
"version": "0.8.4",
"minAppVersion": "1.4.16",
"description": "Easily install a beta version of a plugin for testing.",
"author": "TfTHacker",
"authorUrl": "https://github.com/TfTHacker/obsidian42-brat",
"helpUrl": "https://tfthacker.com/BRAT",
"isDesktopOnly": false,
"fundingUrl": {
"Buy Me a Coffee": "https://bit.ly/o42-kofi",
"Visit my site": "https://tfthacker.com"
}
}
"id": "obsidian42-brat",
"name": "BRAT",
"version": "1.0.1",
"minAppVersion": "1.4.16",
"description": "Easily install a beta version of a plugin for testing.",
"author": "TfTHacker",
"authorUrl": "https://github.com/TfTHacker/obsidian42-brat",
"helpUrl": "https://tfthacker.com/BRAT",
"isDesktopOnly": false,
"fundingUrl": {
"Buy Me a Coffee": "https://bit.ly/o42-kofi",
"Visit my site": "https://tfthacker.com"
}
}