Skip to content

Commit

Permalink
feat(GIST-90): fixed curl command and refactor raw url generation
Browse files Browse the repository at this point in the history
  • Loading branch information
Courtcircuits committed Nov 13, 2024
1 parent d8877ab commit e8d1e38
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 9 deletions.
3 changes: 2 additions & 1 deletion src/app/(gistLayout)/mygist/[gistId]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import React from "react"
import MyGistIdPage from "./page-ui"
import { useGist, usePatchGistContent, usePatchGistName } from "@/lib/queries/gists.queries"
import { useToast } from "@/components/shadcn/use-toast"
import { getRawGistURL } from "@/lib/utils"

interface MyGistIdFeaturePageProps {
params: {
Expand Down Expand Up @@ -67,7 +68,7 @@ export default function MyGistIdFeaturePage({ params }: MyGistIdFeaturePageProps
}

const onCopyCurl = () => {
const curlCommand = `curl https://raw.gists.app/${gistId} | /bin/bash`
const curlCommand = `curl ${getRawGistURL(gistId)} -o- | /bin/bash`
toast({
title: "Gist Copied",
description: "Your curl command has been copied successfully",
Expand Down
3 changes: 2 additions & 1 deletion src/app/(gistLayout)/org/[orgId]/gist/[gistId]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { useToast } from "@/components/shadcn/use-toast"
import GistDetails from "@/components/ui/gist-details"
import { useGist, usePatchGistContent, usePatchGistName } from "@/lib/queries/gists.queries"
import { useOrg } from "@/lib/queries/orgs.queries"
import { getRawGistURL } from "@/lib/utils"
import React from "react"

interface MyOrgGistIdFeaturePageProps {
Expand Down Expand Up @@ -78,7 +79,7 @@ export default function MyOrgGistIdFeaturePage({ params }: MyOrgGistIdFeaturePag
}

const onCopyCurl = () => {
const curlCommand = `curl https://raw.gists.app/${gistId} | /bin/bash`
const curlCommand = `curl ${getRawGistURL(gistId)} -o- | /bin/bash`
toast({
title: "Gist Copied",
description: "Your curl command has been copied successfully",
Expand Down
9 changes: 2 additions & 7 deletions src/components/ui/gist-details.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { useState } from "react"
import { Codearea } from "../shadcn/codearea"
import { getLanguage } from "@/lib/language"
import TooltipShortcut, { TooltipShortcutTrigger } from "./tooltip-shortcut"
import { getBackendURL } from "@/lib/utils"
import { getBackendURL, getRawGistURL } from "@/lib/utils"

Check warning on line 19 in src/components/ui/gist-details.tsx

View workflow job for this annotation

GitHub Actions / Test linting

'getBackendURL' is defined but never used
import { SidebarTrigger } from "../shadcn/sidebar"
import { Button } from "../shadcn/button"

Expand Down Expand Up @@ -56,12 +56,7 @@ export default function GistDetails({
const onOpenPlainText = (gistID: string) => {
// if production go to https://raw.gists.app/{gistID}
console.log(process.env.NODE_ENV)
if (process.env.NODE_ENV === "production") {
const raw_url = getBackendURL().replace("api", "raw") + "/" + gistID
window.open(raw_url, "_blank")
return
}
window.open(getBackendURL() + "/gists/raw/" + gistID, "_blank")
window.open(getRawGistURL(gistID), "_blank")
}

return (
Expand Down
8 changes: 8 additions & 0 deletions src/lib/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,11 @@ export function cn(...inputs: ClassValue[]) {
export function getBackendURL() {
return process.env.NEXT_PUBLIC_BACKEND_URL || "https://api.gists.app"
}

export function getRawGistURL(id: string) {
if (process.env.NODE_ENV === "production") {
const raw_url = getBackendURL().replace("api", "raw") + "/" + id
return raw_url
}
return getBackendURL() + "/gists/raw/" + id
}

0 comments on commit e8d1e38

Please sign in to comment.