-
-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Réactiver le lien vers l'interface Web de Kodi.
- Loading branch information
Showing
3 changed files
with
73 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/** | ||
* @module | ||
*/ | ||
|
||
/** | ||
* Teste si un lien est accessible. | ||
* | ||
* @param {string} url Le lien testé. | ||
* @returns {Promise<boolean>} Une promesse indiquant si le lien est accessible. | ||
*/ | ||
export const ping = async function (url) { | ||
try { | ||
await fetch(url, { | ||
method: "HEAD", | ||
// Fournir des "identifiants" vides dans les entêtes pour que si la | ||
// page demande une authentification : celle-ci échoue directement | ||
// sans demander à l'utilisateur de saisir son identifiant et son | ||
// mot de passe. | ||
headers: { Authorization: "" }, | ||
}); | ||
return true; | ||
} catch { | ||
// Ignorer l'erreur si la requête échoue. Et indiquer que le lien est | ||
// inaccessible. | ||
return false; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import assert from "node:assert"; | ||
import sinon from "sinon"; | ||
import { ping } from "../../../src/tools/ping.js"; | ||
|
||
describe("tools/ping.js", function () { | ||
describe("ping()", function () { | ||
it("should return true", async function () { | ||
const stub = sinon.stub(globalThis, "fetch").resolves(); | ||
|
||
const ok = await ping("http://foo.com/"); | ||
assert.strictEqual(ok, true); | ||
|
||
assert.strictEqual(stub.callCount, 1); | ||
assert.deepStrictEqual(stub.firstCall.args, ["http://foo.com/", { | ||
method: "HEAD", | ||
headers: { Authorization: "" }, | ||
}]); | ||
|
||
stub.restore(); | ||
}); | ||
|
||
it("should return false", async function () { | ||
const stub = sinon.stub(globalThis, "fetch").rejects(); | ||
|
||
const ok = await ping("http://foo.com/"); | ||
assert.strictEqual(ok, false); | ||
|
||
assert.strictEqual(stub.callCount, 1); | ||
assert.deepStrictEqual(stub.firstCall.args, ["http://foo.com/", { | ||
method: "HEAD", | ||
headers: { Authorization: "" }, | ||
}]); | ||
|
||
stub.restore(); | ||
}); | ||
}); | ||
}); |