← back to mibgb65-cloud__snipxn_note

Function bodies 942 total

All specs Real LLM only Function bodies
MainActivity class · kotlin · L11-L32 (22 LOC)
snipxn_app/android/app/src/main/java/com/snipxn/app/MainActivity.kt
class MainActivity : ReactActivity() {

  override fun getMainComponentName(): String = "snipxn_app"

  override fun onCreate(savedInstanceState: Bundle?) {
    supportFragmentManager.fragmentFactory = RNScreensFragmentFactory()
    enableHighRefreshRate()
    super.onCreate(null)
  }

  private fun enableHighRefreshRate() {
    val display = windowManager.defaultDisplay
    val supportedModes = display.supportedModes
    val highRefreshMode = supportedModes.maxByOrNull { it.refreshRate } ?: return
    val params = window.attributes
    params.preferredDisplayModeId = highRefreshMode.modeId
    window.attributes = params
  }

  override fun createReactActivityDelegate(): ReactActivityDelegate =
      DefaultReactActivityDelegate(this, mainComponentName, fabricEnabled)
}
MainApplication class · kotlin · L10-L30 (21 LOC)
snipxn_app/android/app/src/main/java/com/snipxn/app/MainApplication.kt
class MainApplication : Application(), ReactApplication {

  override val reactHost: ReactHost by lazy {
    getDefaultReactHost(
      context = applicationContext,
      packageList =
        PackageList(this).packages.apply {
          // Packages that cannot be autolinked yet can be added manually here, for example:
          // add(MyReactNativePackage())
        },
    )
  }

  override fun onCreate() {
    super.onCreate()
    loadReactNative(this)
    if (BuildConfig.DEBUG) {
      reactHost.setBundleSource("localhost:8081", "index")
    }
  }
}
App function · typescript · L22-L32 (11 LOC)
snipxn_app/App.tsx
function App() {
  return (
    <GestureHandlerRootView style={{ flex: 1 }}>
      <SafeAreaProvider>
        <ThemeProvider>
          <AppContent />
        </ThemeProvider>
      </SafeAreaProvider>
    </GestureHandlerRootView>
  );
}
delay function · typescript · L34-L38 (5 LOC)
snipxn_app/App.tsx
function delay(ms: number): Promise<void> {
  return new Promise(resolve => {
    setTimeout(resolve, ms);
  });
}
AppContent function · typescript · L40-L139 (100 LOC)
snipxn_app/App.tsx
function AppContent() {
  const hydrateLanguage = useI18nStore(state => state.hydrateLanguage);
  const restoreSession = useAuthStore(state => state.restoreSession);
  const { syncNow, setOffline } = useSyncStore(useShallow(state => ({
    syncNow: state.syncNow,
    setOffline: state.setOffline,
  })));
  const checkForUpdates = useAppUpdateStore(state => state.checkForUpdates);
  const { palette, typography } = useAppTheme();
  const { t } = useI18n();
  const [appReady, setAppReady] = useState(false);

  useEffect(() => {
    let mounted = true;

    const runBackgroundStartupTasks = async () => {
      try {
        const online = await isOnline();

        if (!online) {
          setOffline();
          return;
        }

        await checkForUpdates();

        if (useAuthStore.getState().isAuthenticated) {
          await syncNow();
        }
      } catch (error) {
        console.warn('Background startup tasks failed.', error);
      }
    };

    startNetworkMonitor(() => {
AppDelegate class · swift · L7-L34 (28 LOC)
snipxn_app/ios/snipxn_app/AppDelegate.swift
class AppDelegate: UIResponder, UIApplicationDelegate {
  var window: UIWindow?

  var reactNativeDelegate: ReactNativeDelegate?
  var reactNativeFactory: RCTReactNativeFactory?

  func application(
    _ application: UIApplication,
    didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? = nil
  ) -> Bool {
    let delegate = ReactNativeDelegate()
    let factory = RCTReactNativeFactory(delegate: delegate)
    delegate.dependencyProvider = RCTAppDependencyProvider()

    reactNativeDelegate = delegate
    reactNativeFactory = factory

    window = UIWindow(frame: UIScreen.main.bounds)

    factory.startReactNative(
      withModuleName: "snipxn_app",
      in: window,
      launchOptions: launchOptions
    )

    return true
  }
}
ReactNativeDelegate class · swift · L36-L48 (13 LOC)
snipxn_app/ios/snipxn_app/AppDelegate.swift
class ReactNativeDelegate: RCTDefaultReactNativeFactoryDelegate {
  override func sourceURL(for bridge: RCTBridge) -> URL? {
    self.bundleURL()
  }

  override func bundleURL() -> URL? {
#if DEBUG
    RCTBundleURLProvider.sharedSettings().jsBundleURL(forBundleRoot: "index")
#else
    Bundle.main.url(forResource: "main", withExtension: "jsbundle")
#endif
  }
}
Repobility (the analyzer behind this table) · https://repobility.com
ensureDir function · javascript · L35-L37 (3 LOC)
snipxn_app/scripts/generate-android-branding.js
function ensureDir(dirPath) {
  fs.mkdirSync(dirPath, { recursive: true });
}
writeText function · javascript · L39-L42 (4 LOC)
snipxn_app/scripts/generate-android-branding.js
function writeText(filePath, content) {
  ensureDir(path.dirname(filePath));
  fs.writeFileSync(filePath, content, 'utf8');
}
iconSvg function · javascript · L44-L65 (22 LOC)
snipxn_app/scripts/generate-android-branding.js
function iconSvg() {
  return `
  <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1024 1024">
    <defs>
      <linearGradient id="bg" x1="140" y1="120" x2="860" y2="900" gradientUnits="userSpaceOnUse">
        <stop offset="0%" stop-color="${COLORS.slate800}" />
        <stop offset="55%" stop-color="${COLORS.slate900}" />
        <stop offset="100%" stop-color="#020617" />
      </linearGradient>
    </defs>
    <rect width="1024" height="1024" rx="248" fill="url(#bg)" />
    <circle cx="810" cy="226" r="130" fill="${COLORS.amber}" opacity="0.14" />
    <circle cx="260" cy="824" r="150" fill="${COLORS.emerald}" opacity="0.08" />
    <rect x="74" y="74" width="876" height="876" rx="210" fill="none" stroke="${COLORS.slate700}" stroke-opacity="0.45" stroke-width="8" />
    <g fill="none" stroke-linecap="round" stroke-linejoin="round">
      <polyline points="372,286 240,512 372,738" stroke="${COLORS.white}" stroke-width="94" />
      <line x1="470" y1="760" x2="604" y2="264" stroke
markSvg function · javascript · L67-L77 (11 LOC)
snipxn_app/scripts/generate-android-branding.js
function markSvg() {
  return `
  <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1024 1024">
    <g fill="none" stroke-linecap="round" stroke-linejoin="round">
      <polyline points="388,290 280,512 388,734" stroke="${COLORS.white}" stroke-width="86" />
      <line x1="478" y1="738" x2="594" y2="286" stroke="${COLORS.white}" stroke-width="74" />
      <polyline points="644,290 752,512 644,734" stroke="${COLORS.amber}" stroke-width="86" />
    </g>
    <circle cx="740" cy="764" r="34" fill="${COLORS.amber}" />
  </svg>`;
}
renderPng function · javascript · L79-L85 (7 LOC)
snipxn_app/scripts/generate-android-branding.js
async function renderPng(svg, size, outputPath) {
  ensureDir(path.dirname(outputPath));
  await sharp(Buffer.from(svg))
    .resize(size, size)
    .png()
    .toFile(outputPath);
}
main function · javascript · L87-L140 (54 LOC)
snipxn_app/scripts/generate-android-branding.js
async function main() {
  const iconSource = iconSvg();
  const markSource = markSvg();

  writeText(path.join(brandingRoot, 'snipxn-app-icon.svg'), iconSource);
  writeText(path.join(brandingRoot, 'snipxn-mark.svg'), markSource);

  for (const [density, size] of Object.entries(densities)) {
    const mipmapDir = path.join(resRoot, `mipmap-${density}`);
    await renderPng(iconSource, size, path.join(mipmapDir, 'ic_launcher.png'));
    await renderPng(iconSource, size, path.join(mipmapDir, 'ic_launcher_round.png'));
  }

  for (const [density, size] of Object.entries(adaptiveForegroundSizes)) {
    const mipmapDir = path.join(resRoot, `mipmap-${density}`);
    await renderPng(markSource, size, path.join(mipmapDir, 'ic_launcher_foreground.png'));
  }

  await renderPng(markSource, 320, path.join(resRoot, 'drawable', 'bootsplash_logo.png'));

  writeText(
    path.join(resRoot, 'mipmap-anydpi-v26', 'ic_launcher.xml'),
    `<?xml version="1.0" encoding="utf-8"?>
<adaptive-icon xmlns:andro
normalizeAiResponse function · typescript · L19-L36 (18 LOC)
snipxn_app/src/api/ai.ts
function normalizeAiResponse(response: RawAiResponse | string | null | undefined): AiResponse {
  if (typeof response === 'string') {
    return {
      content: response,
      model: null,
      totalTokens: null,
    };
  }

  return {
    content: typeof response?.content === 'string' ? response.content : '',
    model: typeof response?.model === 'string' ? response.model : null,
    totalTokens:
      typeof response?.totalTokens === 'number' && Number.isFinite(response.totalTokens)
        ? response.totalTokens
        : null,
  };
}
review function · typescript · L38-L45 (8 LOC)
snipxn_app/src/api/ai.ts
export async function review(req: ReviewRequest): Promise<ReviewResponse> {
  const response = await apiClient.post<RawAiResponse | string, ReviewRequest>(
    `${AI_BASE_URL}/review`,
    req,
  );

  return normalizeAiResponse(response);
}
Want fix-PRs on findings? Install Repobility's GitHub App · github.com/apps/repobility-bot
generate function · typescript · L47-L54 (8 LOC)
snipxn_app/src/api/ai.ts
export async function generate(req: GenerateRequest): Promise<GenerateResponse> {
  const response = await apiClient.post<RawAiResponse | string, GenerateRequest>(
    `${AI_BASE_URL}/generate`,
    req,
  );

  return normalizeAiResponse(response);
}
checkLatestVersion function · typescript · L5-L14 (10 LOC)
snipxn_app/src/api/appVersion.ts
export async function checkLatestVersion(
  platform: AppVersionPlatform,
): Promise<AppVersionResponse | null> {
  const response = await apiClient.get<AppVersionResponse | null>(
    '/app/version/latest',
    { params: { platform } },
  );

  return response ?? null;
}
normalizeLoginResponse function · typescript · L44-L71 (28 LOC)
snipxn_app/src/api/auth.ts
function normalizeLoginResponse(response: RawLoginResponse): LoginResponse {
  const nickname = response.user.nickname?.trim() ?? '';

  return {
    accessToken: response.token.accessToken,
    refreshToken: response.token.refreshToken,
    isNewUser: nickname.length === 0,
    userInfo: {
      id: response.user.id,
      email: response.user.email ?? null,
      nickname: response.user.nickname,
      avatar: response.user.avatar,
      bio: response.user.bio,
      gender: response.user.gender ?? null,
      birthday: response.user.birthday ?? null,
      website: response.user.website ?? null,
      github: response.user.github ?? null,
      location: response.user.location ?? null,
      company: response.user.company ?? null,
      techStack: response.user.techStack ?? null,
      storageUsed: response.user.storageUsed,
      storageLimit: response.user.storageLimit,
      status: response.user.status ?? null,
      createdAt: response.user.createdAt ?? null,
      updatedAt: r
checkEmail function · typescript · L73-L78 (6 LOC)
snipxn_app/src/api/auth.ts
export function checkEmail(email: string): Promise<CheckEmailResponse> {
  return apiClient.post<CheckEmailResponse, CheckEmailRequest>(
    `${AUTH_BASE_URL}/check-email`,
    { email },
  );
}
sendCode function · typescript · L80-L82 (3 LOC)
snipxn_app/src/api/auth.ts
export function sendCode(req: SendCodeRequest): Promise<void> {
  return apiClient.post<void, SendCodeRequest>(`${AUTH_BASE_URL}/code`, req);
}
register function · typescript · L84-L86 (3 LOC)
snipxn_app/src/api/auth.ts
export function register(req: RegisterRequest): Promise<void> {
  return apiClient.post<void, RegisterRequest>(`${AUTH_BASE_URL}/register`, req);
}
login function · typescript · L88-L95 (8 LOC)
snipxn_app/src/api/auth.ts
export async function login(req: LoginRequest): Promise<LoginResponse> {
  const response = await apiClient.post<RawLoginResponse, LoginRequest>(
    `${AUTH_BASE_URL}/login`,
    req,
  );

  return normalizeLoginResponse(response);
}
refresh function · typescript · L97-L102 (6 LOC)
snipxn_app/src/api/auth.ts
export function refresh(req: RefreshTokenRequest): Promise<TokenResponse> {
  return apiClient.post<TokenResponse, RefreshTokenRequest>(
    `${AUTH_BASE_URL}/refresh`,
    req,
  );
}
Repobility — the code-quality scanner for AI-generated software · https://repobility.com
resetPassword function · typescript · L104-L109 (6 LOC)
snipxn_app/src/api/auth.ts
export function resetPassword(req: ResetPasswordRequest): Promise<void> {
  return apiClient.post<void, ResetPasswordRequest>(
    `${AUTH_BASE_URL}/reset-password`,
    req,
  );
}
logout function · typescript · L111-L113 (3 LOC)
snipxn_app/src/api/auth.ts
export function logout(): Promise<void> {
  return apiClient.post<void>(`${AUTH_BASE_URL}/logout`);
}
oauthGithub function · typescript · L115-L129 (15 LOC)
snipxn_app/src/api/auth.ts
export function oauthGithub(
  code: string,
  redirectUri: string,
  deviceId: string,
  deviceName: string,
): Promise<LoginResponse> {
  return apiClient
    .post<RawLoginResponse, OAuthLoginRequest>(`${AUTH_BASE_URL}/oauth/github`, {
      code,
      redirectUri,
      deviceId,
      deviceName,
    })
    .then(normalizeLoginResponse);
}
oauthGoogle function · typescript · L131-L145 (15 LOC)
snipxn_app/src/api/auth.ts
export function oauthGoogle(
  code: string,
  redirectUri: string,
  deviceId: string,
  deviceName: string,
): Promise<LoginResponse> {
  return apiClient
    .post<RawLoginResponse, OAuthLoginRequest>(`${AUTH_BASE_URL}/oauth/google`, {
      code,
      redirectUri,
      deviceId,
      deviceName,
    })
    .then(normalizeLoginResponse);
}
resolveBaseUrl function · typescript · L79-L81 (3 LOC)
snipxn_app/src/api/axios.ts
function resolveBaseUrl(): string {
  return __DEV__ ? DEV_API_BASE_URL : PROD_API_BASE_URL;
}
isApiResult function · typescript · L83-L95 (13 LOC)
snipxn_app/src/api/axios.ts
function isApiResult<T>(value: unknown): value is ApiResult<T> {
  if (typeof value !== 'object' || value === null) {
    return false;
  }

  return (
    'code' in value &&
    typeof value.code === 'number' &&
    'message' in value &&
    typeof value.message === 'string' &&
    'data' in value
  );
}
unwrapApiResult function · typescript · L97-L99 (3 LOC)
snipxn_app/src/api/axios.ts
function unwrapApiResult<T>(value: ApiResult<T> | T): T {
  return isApiResult<T>(value) ? value.data : value;
}
extractApiError function · typescript · L101-L118 (18 LOC)
snipxn_app/src/api/axios.ts
function extractApiError(value: unknown): ApiError | null {
  if (typeof value !== 'object' || value === null) {
    return null;
  }

  const code = 'code' in value && typeof value.code === 'number' ? value.code : null;
  const message =
    'message' in value && typeof value.message === 'string' ? value.message : null;

  if (code === null && message === null) {
    return null;
  }

  return {
    code: code ?? -1,
    message: message ?? '请求失败',
  };
}
Repobility · code-quality intelligence platform · https://repobility.com
normalizeApiError function · typescript · L120-L161 (42 LOC)
snipxn_app/src/api/axios.ts
function normalizeApiError(error: unknown): ApiError {
  const fallbackError = {
    code: -1,
    message: '请求失败',
  } satisfies ApiError;

  if (axios.isAxiosError(error)) {
    const responseError = extractApiError(error.response?.data);

    if (responseError !== null) {
      return responseError;
    }

    if (error.code === 'ECONNABORTED') {
      return {
        code: error.response?.status ?? -1,
        message: '请求超时',
      };
    }

    if (error.message === 'Network Error') {
      return {
        code: error.response?.status ?? -1,
        message: '网络连接失败',
      };
    }

    return {
      code: error.response?.status ?? -1,
      message: error.message || fallbackError.message,
    };
  }

  if (error instanceof Error) {
    return {
      code: -1,
      message: error.message || fallbackError.message,
    };
  }

  return fallbackError;
}
isRefreshRequest function · typescript · L163-L165 (3 LOC)
snipxn_app/src/api/axios.ts
function isRefreshRequest(config?: Pick<AxiosRequestConfig, 'url'>): boolean {
  return config?.url?.includes(REFRESH_ENDPOINT) ?? false;
}
getStoredAuthTokens function · typescript · L167-L193 (27 LOC)
snipxn_app/src/api/axios.ts
export async function getStoredAuthTokens(): Promise<StoredAuthTokens | null> {
  const credentials = await Keychain.getGenericPassword({
    service: AUTH_KEYCHAIN_SERVICE,
  });

  if (!credentials) {
    return null;
  }

  try {
    const parsed = JSON.parse(credentials.password) as Partial<StoredAuthTokens>;

    if (
      typeof parsed.accessToken !== 'string' ||
      typeof parsed.refreshToken !== 'string'
    ) {
      return null;
    }

    return {
      accessToken: parsed.accessToken,
      refreshToken: parsed.refreshToken,
    };
  } catch {
    return null;
  }
}
saveAuthTokens function · typescript · L195-L207 (13 LOC)
snipxn_app/src/api/axios.ts
export async function saveAuthTokens(tokens: StoredAuthTokens): Promise<void> {
  const result = await Keychain.setGenericPassword(
    AUTH_KEYCHAIN_USERNAME,
    JSON.stringify(tokens),
    {
      service: AUTH_KEYCHAIN_SERVICE,
    },
  );

  if (!result) {
    throw new Error('保存登录凭证失败');
  }
}
clearAuthTokens function · typescript · L209-L213 (5 LOC)
snipxn_app/src/api/axios.ts
export async function clearAuthTokens(): Promise<void> {
  await Keychain.resetGenericPassword({
    service: AUTH_KEYCHAIN_SERVICE,
  });
}
setUnauthorizedHandler function · typescript · L215-L217 (3 LOC)
snipxn_app/src/api/axios.ts
export function setUnauthorizedHandler(handler: UnauthorizedHandler): void {
  unauthorizedHandler = handler;
}
handleUnauthorized function · typescript · L219-L225 (7 LOC)
snipxn_app/src/api/axios.ts
async function handleUnauthorized(): Promise<void> {
  await useAuthStore.getState().clearAuth();

  if (unauthorizedHandler !== null) {
    await Promise.resolve(unauthorizedHandler());
  }
}
attachAccessToken function · typescript · L227-L242 (16 LOC)
snipxn_app/src/api/axios.ts
async function attachAccessToken(
  config: InternalAxiosRequestConfig,
): Promise<InternalAxiosRequestConfig> {
  const storedTokens = await getStoredAuthTokens();
  const accessToken = storedTokens?.accessToken ?? useAuthStore.getState().accessToken;

  if (!accessToken) {
    return config;
  }

  const headers = AxiosHeaders.from(config.headers);
  headers.set('Authorization', `Bearer ${accessToken}`);
  config.headers = headers;

  return config;
}
Repobility (the analyzer behind this table) · https://repobility.com
refreshAccessToken function · typescript · L252-L296 (45 LOC)
snipxn_app/src/api/axios.ts
async function refreshAccessToken(): Promise<string> {
  if (refreshPromise !== null) {
    return refreshPromise;
  }

  refreshPromise = (async () => {
    const storedTokens = await getStoredAuthTokens();
    const refreshToken =
      storedTokens?.refreshToken ?? useAuthStore.getState().refreshToken;

    if (!refreshToken) {
      throw new Error('缺少 refreshToken');
    }

    const deviceId = await getDeviceId();
    const payload: RefreshTokenRequest = {
      refreshToken,
      deviceId,
    };

    const response = await rawClient.post<
      ApiResult<TokenResponse>,
      AxiosResponse<ApiResult<TokenResponse>>,
      RefreshTokenRequest
    >(REFRESH_ENDPOINT, payload);
    const tokens = unwrapApiResult(response.data);

    await saveAuthTokens(tokens);

    const authStore = useAuthStore.getState();
    authStore.setAccessToken(tokens.accessToken);
    authStore.setRefreshToken(tokens.refreshToken);

    return tokens.accessToken;
  })()
    .catch(async error => {
    
listComments function · typescript · L10-L17 (8 LOC)
snipxn_app/src/api/comment.ts
export function listComments(
  postId: string,
  params: CommentListParams = {},
): Promise<PageResult<CommentResponse>> {
  return apiClient.get<PageResult<CommentResponse>>(`/posts/${postId}/comments`, {
    params,
  });
}
listReplies function · typescript · L19-L30 (12 LOC)
snipxn_app/src/api/comment.ts
export function listReplies(
  postId: string,
  commentId: string,
  params: CommentListParams = {},
): Promise<PageResult<CommentResponse>> {
  return apiClient.get<PageResult<CommentResponse>>(
    `/posts/${postId}/comments/${commentId}/replies`,
    {
      params,
    },
  );
}
createComment function · typescript · L32-L40 (9 LOC)
snipxn_app/src/api/comment.ts
export function createComment(
  postId: string,
  req: CreateCommentRequest,
): Promise<CommentResponse> {
  return apiClient.post<CommentResponse, CreateCommentRequest>(
    `/posts/${postId}/comments`,
    req,
  );
}
deleteComment function · typescript · L42-L44 (3 LOC)
snipxn_app/src/api/comment.ts
export function deleteComment(postId: string, commentId: string): Promise<void> {
  return apiClient.delete<void>(`/posts/${postId}/comments/${commentId}`);
}
likeComment function · typescript · L46-L48 (3 LOC)
snipxn_app/src/api/comment.ts
export function likeComment(postId: string, commentId: string): Promise<void> {
  return apiClient.post<void>(`/posts/${postId}/comments/${commentId}/like`);
}
unlikeComment function · typescript · L50-L52 (3 LOC)
snipxn_app/src/api/comment.ts
export function unlikeComment(postId: string, commentId: string): Promise<void> {
  return apiClient.delete<void>(`/posts/${postId}/comments/${commentId}/like`);
}
uploadFile function · typescript · L7-L13 (7 LOC)
snipxn_app/src/api/file.ts
export function uploadFile(file: FormData): Promise<UploadResponse> {
  return apiClient.post<UploadResponse, FormData>(FILES_BASE_URL, file, {
    headers: {
      'Content-Type': 'multipart/form-data',
    },
  });
}
Want fix-PRs on findings? Install Repobility's GitHub App · github.com/apps/repobility-bot
getFileUrl function · typescript · L15-L17 (3 LOC)
snipxn_app/src/api/file.ts
export function getFileUrl(fileId: string): string {
  return `${API_BASE_URL}${FILES_BASE_URL}/${encodeURIComponent(fileId)}`;
}
listFolders function · typescript · L7-L9 (3 LOC)
snipxn_app/src/api/folder.ts
export function listFolders(): Promise<FolderResponse[]> {
  return apiClient.get<FolderResponse[]>(FOLDERS_BASE_URL);
}
createFolder function · typescript · L11-L13 (3 LOC)
snipxn_app/src/api/folder.ts
export function createFolder(req: CreateFolderRequest): Promise<FolderResponse> {
  return apiClient.post<FolderResponse, CreateFolderRequest>(FOLDERS_BASE_URL, req);
}
page 1 / 19next ›