Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,10 @@ package project

import (
"context"
"crypto/rand"
"encoding/base64"
"fmt"
"io"

"menlo.ai/jan-api-gateway/app/domain/query"
"menlo.ai/jan-api-gateway/app/utils/stringutils"
)

// ProjectService provides business logic for managing projects.
Expand All @@ -24,14 +22,11 @@ func NewService(repo ProjectRepository) *ProjectService {

// createPublicID generates a unique, URL-safe public ID for the project.
func (s *ProjectService) createPublicID() (string, error) {
randomBytes := make([]byte, 16)
_, err := io.ReadFull(rand.Reader, randomBytes)
randomStr, err := stringutils.RandomString(16)
if err != nil {
return "", fmt.Errorf("failed to generate random bytes for public ID: %w", err)
return "", err
}

publicID := base64.URLEncoding.EncodeToString(randomBytes)
return publicID, nil
return fmt.Sprintf("proj_%s", randomStr), nil
}

// CreateProjectWithPublicID creates a new project and automatically
Expand Down Expand Up @@ -80,7 +75,7 @@ func (s *ProjectService) FindProjectByPublicID(ctx context.Context, publicID str
}

// FindProjects retrieves a list of projects based on a filter and pagination.
func (s *ProjectService) FindProjects(ctx context.Context, filter ProjectFilter, pagination *query.Pagination) ([]*Project, error) {
func (s *ProjectService) Find(ctx context.Context, filter ProjectFilter, pagination *query.Pagination) ([]*Project, error) {
return s.repo.FindByFilter(ctx, filter, pagination)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ package openai
type ObjectKey string

const (
OrganizationAdminApiKey ObjectKey = "organization.admin_api_key"
ObjectKeyAdminApiKey ObjectKey = "organization.admin_api_key"
ObjectKeyProject ObjectKey = "organization.project"
)

type OwnerType string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"menlo.ai/jan-api-gateway/app/interfaces/http/routes/v1/mcp"
mcp_impl "menlo.ai/jan-api-gateway/app/interfaces/http/routes/v1/mcp/mcp_impl"
"menlo.ai/jan-api-gateway/app/interfaces/http/routes/v1/organization"
"menlo.ai/jan-api-gateway/app/interfaces/http/routes/v1/organization/projects"
)

var RouteProvider = wire.NewSet(
Expand All @@ -23,6 +24,7 @@ var RouteProvider = wire.NewSet(
janV1Auth.NewAuthRoute,
janV1.NewV1Route,
jan.NewJanRoute,
projects.NewProjectsRoute,
organization.NewAdminApiKeyAPI,
organization.NewOrganizationRoute,
mcp_impl.NewSerperMCP,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ func domainToOrganizationAdminAPIKeyResponse(entity *apikey.ApiKey) Organization
lastUsedAt = ptr.ToInt64(entity.LastUsedAt.Unix())
}
return OrganizationAdminAPIKeyResponse{
Object: string(openai.OrganizationAdminApiKey),
Object: string(openai.ObjectKeyAdminApiKey),
ID: entity.PublicID,
Name: entity.Description,
RedactedValue: entity.PlaintextHint,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,23 @@ package organization

import (
"github.com/gin-gonic/gin"
"menlo.ai/jan-api-gateway/app/interfaces/http/routes/v1/organization/projects"
)

type OrganizationRoute struct {
adminApiKeyAPI *AdminApiKeyAPI
projectsRoute *projects.ProjectsRoute
}

func NewOrganizationRoute(adminApiKeyAPI *AdminApiKeyAPI) *OrganizationRoute {
func NewOrganizationRoute(adminApiKeyAPI *AdminApiKeyAPI, projectsRoute *projects.ProjectsRoute) *OrganizationRoute {
return &OrganizationRoute{
adminApiKeyAPI,
projectsRoute,
}
}

func (organizationRoute *OrganizationRoute) RegisterRouter(router gin.IRouter) {
organizationRouter := router.Group("/organization")
organizationRoute.adminApiKeyAPI.RegisterRouter(organizationRouter)
organizationRoute.projectsRoute.RegisterRouter(organizationRouter)
}
Loading
Loading