mirror of
https://github.com/wassname/talk.git
synced 2026-07-17 11:33:39 +08:00
Merge pull request #2052 from coralproject/next-common
[next] Move common functions to talk-common
This commit is contained in:
@@ -1,6 +1,9 @@
|
||||
import { EventEmitter2 } from "eventemitter2";
|
||||
import qs from "query-string";
|
||||
|
||||
import ensureNoEndSlash from "talk-common/utils/ensureNoEndSlash";
|
||||
import urls from "talk-framework/helpers/urls";
|
||||
|
||||
import {
|
||||
Decorator,
|
||||
withAutoHeight,
|
||||
@@ -15,13 +18,6 @@ import PymControl, {
|
||||
defaultPymControlFactory,
|
||||
PymControlFactory,
|
||||
} from "./PymControl";
|
||||
import { ensureNoEndSlash } from "./utils";
|
||||
|
||||
// This is importing the url helper from the framework using a relative path
|
||||
// import because the ts paths are not configured to use the framework for this
|
||||
// target.
|
||||
// TODO: (wyattjoh) replace with import from framework when we include it in the config.
|
||||
import urls from "../framework/helpers/urls";
|
||||
|
||||
export interface StreamEmbedConfig {
|
||||
storyID?: string;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import qs from "query-string";
|
||||
|
||||
import { buildURL } from "../utils";
|
||||
import { buildURL } from "talk-framework/utils";
|
||||
import { Decorator } from "./types";
|
||||
|
||||
function getCurrentCommentID() {
|
||||
|
||||
@@ -3,7 +3,11 @@
|
||||
"compilerOptions": {
|
||||
"lib": ["dom", "es5"],
|
||||
"types": ["jest", "node"],
|
||||
"paths": {}
|
||||
"baseUrl": "./",
|
||||
"paths": {
|
||||
"talk-common/*": ["../../common/*"],
|
||||
"talk-framework/*": ["../framework/*"]
|
||||
}
|
||||
},
|
||||
"include": [
|
||||
"./**/*",
|
||||
|
||||
@@ -1,18 +0,0 @@
|
||||
import buildURL from "./buildURL";
|
||||
|
||||
it("should default to window.location", () => {
|
||||
const url = buildURL();
|
||||
expect(url).toBe("http://localhost/");
|
||||
});
|
||||
|
||||
it("should build from parameters", () => {
|
||||
const url = buildURL({
|
||||
protocol: "https",
|
||||
hostname: "hostname",
|
||||
port: "8080",
|
||||
pathname: "/pathname",
|
||||
search: "search",
|
||||
hash: "#hash",
|
||||
});
|
||||
expect(url).toBe("https//hostname:8080/pathname?search#hash");
|
||||
});
|
||||
@@ -1,17 +0,0 @@
|
||||
export default function buildURL({
|
||||
protocol = window.location.protocol,
|
||||
hostname = window.location.hostname,
|
||||
port = window.location.port,
|
||||
pathname = window.location.pathname,
|
||||
search = window.location.search,
|
||||
hash = window.location.hash,
|
||||
} = {}) {
|
||||
if (search && search[0] !== "?") {
|
||||
search = `?${search}`;
|
||||
} else if (search === "?") {
|
||||
search = "";
|
||||
}
|
||||
return `${protocol}//${hostname}${
|
||||
port ? `:${port}` : ""
|
||||
}${pathname}${search}${hash}`;
|
||||
}
|
||||
@@ -1,6 +1,2 @@
|
||||
export { default as buildURL } from "./buildURL";
|
||||
export { default as ensureEndSlash } from "./ensureEndSlash";
|
||||
export { default as ensureNoEndSlash } from "./ensureNoEndSlash";
|
||||
export { default as startsWith } from "./startsWith";
|
||||
export { default as prefixStorage } from "./prefixStorage";
|
||||
export { default as parseHashQuery } from "./parseHashQuery";
|
||||
|
||||
@@ -1,24 +0,0 @@
|
||||
import parseHashQuery from "./parseHashQuery";
|
||||
|
||||
it("should parse hash", () => {
|
||||
const testCases: Array<[string, ReturnType<typeof parseHashQuery>]> = [
|
||||
[
|
||||
"#commentID=comment-id",
|
||||
{
|
||||
commentID: "comment-id",
|
||||
},
|
||||
],
|
||||
[
|
||||
"#commentID=comment-id&storyURL=story-url",
|
||||
{
|
||||
commentID: "comment-id",
|
||||
storyURL: "story-url",
|
||||
},
|
||||
],
|
||||
["#", {}],
|
||||
["", {}],
|
||||
];
|
||||
testCases.forEach(tc => {
|
||||
expect(parseHashQuery(tc[0])).toEqual(tc[1]);
|
||||
});
|
||||
});
|
||||
@@ -1,5 +0,0 @@
|
||||
import qs from "query-string";
|
||||
|
||||
export default function parseQueryHash(hash: string): Record<string, string> {
|
||||
return qs.parse(hash);
|
||||
}
|
||||
@@ -3,3 +3,5 @@ export { default as animationFrame } from "./animationFrame";
|
||||
export { default as pascalCase } from "./pascalCase";
|
||||
export { default as oncePerFrame } from "./oncePerFrame";
|
||||
export { default as isBeforeDate } from "./isBeforeDate";
|
||||
export { default as ensureEndSlash } from "./ensureEndSlash";
|
||||
export { default as ensureNoEndSlash } from "./ensureNoEndSlash";
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
import fetch from "node-fetch";
|
||||
import { URL } from "url";
|
||||
|
||||
import { ensureNoEndSlash } from "talk-common/utils";
|
||||
|
||||
/**
|
||||
* Configuration that Talk is expecting.
|
||||
*/
|
||||
@@ -35,8 +37,7 @@ export async function discover(
|
||||
// Any provider MUST provide a .well-known url that is JSON parsable based
|
||||
// on the issuer: https://openid.net/specs/openid-connect-discovery-1_0.html#ProviderConfig
|
||||
const configurationURL =
|
||||
issuer.origin +
|
||||
issuer.pathname.replace(/\/$/, "") +
|
||||
ensureNoEndSlash(issuer.origin + issuer.pathname) +
|
||||
"/.well-known/openid-configuration";
|
||||
const res = await fetch(configurationURL);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user