-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
496 additions
and
414 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -46,4 +46,5 @@ web/dbdir | |
|
||
# Binaries | ||
/main | ||
/gempbot | ||
/gempbot | ||
/internal/ysweet/createToken.cjs |
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
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,54 @@ | ||
package ysweet | ||
|
||
import ( | ||
"bytes" | ||
_ "embed" | ||
"encoding/json" | ||
"fmt" | ||
"os/exec" | ||
) | ||
|
||
//go:embed createToken.cjs | ||
var createToken string | ||
|
||
type Factory struct { | ||
ysweetUrl string | ||
} | ||
|
||
func NewFactory(ysweetUrl string) *Factory { | ||
return &Factory{ | ||
ysweetUrl: ysweetUrl, | ||
} | ||
} | ||
|
||
type TokenResponse struct { | ||
Url string `json:"url"` | ||
DocId string `json:"docId"` | ||
Token string `json:"token"` | ||
} | ||
|
||
func (f *Factory) CreateToken(docID string) (TokenResponse, error) { | ||
cmd := exec.Command("node", "-", "") | ||
cmd.Env = append(cmd.Env, "YSWEET_URL="+f.ysweetUrl) | ||
cmd.Env = append(cmd.Env, "YSWEET_DOC_ID=1"+docID) | ||
|
||
cmd.Stdin = bytes.NewBufferString(createToken) | ||
|
||
var out bytes.Buffer | ||
var errOut bytes.Buffer | ||
cmd.Stdout = &out | ||
cmd.Stderr = &errOut | ||
|
||
err := cmd.Run() | ||
if err != nil { | ||
return TokenResponse{}, fmt.Errorf("%s %w", errOut.String(), err) | ||
} | ||
|
||
var tokenResponse TokenResponse | ||
err = json.Unmarshal(out.Bytes(), &tokenResponse) | ||
if err != nil { | ||
return TokenResponse{}, fmt.Errorf("%s %w", out.String(), err) | ||
} | ||
|
||
return tokenResponse, nil | ||
} |
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,11 @@ | ||
import { DocumentManager } from '@y-sweet/sdk'; | ||
|
||
const manager = new DocumentManager(process.env.YSWEET_URL); | ||
|
||
async function main() { | ||
const clientToken = await manager.getOrCreateDocAndToken(process.env.YSWEET_DOC_ID) | ||
|
||
console.log(JSON.stringify(clientToken)); | ||
} | ||
|
||
main(); |
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
Oops, something went wrong.