Val Town Code SearchReturn to Val Town

API Access

You can access search results via JSON API by adding format=json to your query:

https://codesearch.val.run/image-url.jpg%20%22Optional%20title%22?q=api&page=202&format=json

For typeahead suggestions, use the /typeahead endpoint:

https://codesearch.val.run/typeahead?q=api

Returns an array of strings in format "username" or "username/projectName"

Found 18017 results for "api"(1080ms)

Reubensubmissions.ts28 matches

@reubenoguta_Valtownโ€ขUpdated 4 days ago
1import { Hono } from "https://esm.sh/hono@3.11.7";
2import type { SubmitExamRequest, ApiResponse, User, ExamSubmission, Question, GradeResult } from "../../shared/types.ts";
3import * as db from "../database/queries.ts";
4import { requireAuth, requireInstructor } from "./auth.ts";
65
66 if (isNaN(examId)) {
67 return c.json<ApiResponse>({ success: false, error: "Invalid exam ID" }, 400);
68 }
69
70 if (user.role !== 'student') {
71 return c.json<ApiResponse>({ success: false, error: "Only students can submit exams" }, 403);
72 }
73
75 const exam = await db.getExamById(examId);
76 if (!exam) {
77 return c.json<ApiResponse>({ success: false, error: "Exam not found" }, 404);
78 }
79
80 if (!exam.is_published) {
81 return c.json<ApiResponse>({ success: false, error: "Exam is not published" }, 403);
82 }
83
85 const enrolled = await db.isUserEnrolled(user.id, exam.course_id);
86 if (!enrolled) {
87 return c.json<ApiResponse>({ success: false, error: "Not enrolled in this course" }, 403);
88 }
89
91 const existingSubmission = await db.getSubmission(examId, user.id);
92 if (existingSubmission) {
93 return c.json<ApiResponse>({ success: false, error: "Exam already submitted" }, 400);
94 }
95
99 const now = new Date();
100 if (now > dueDate) {
101 return c.json<ApiResponse>({ success: false, error: "Exam deadline has passed" }, 400);
102 }
103 }
137 }
138
139 return c.json<ApiResponse<{ submission: ExamSubmission; gradeResults: GradeResult[] }>>({
140 success: true,
141 data: { submission, gradeResults }
143 } catch (error) {
144 console.error("Submit exam error:", error);
145 return c.json<ApiResponse>({ success: false, error: "Failed to submit exam" }, 500);
146 }
147});
154
155 if (isNaN(examId)) {
156 return c.json<ApiResponse>({ success: false, error: "Invalid exam ID" }, 400);
157 }
158
160 const exam = await db.getExamById(examId);
161 if (!exam) {
162 return c.json<ApiResponse>({ success: false, error: "Exam not found" }, 404);
163 }
164
165 const course = await db.getCourseById(exam.course_id);
166 if (!course || course.instructor_id !== user.id) {
167 return c.json<ApiResponse>({ success: false, error: "Access denied" }, 403);
168 }
169
170 const submissionList = await db.getExamSubmissions(examId);
171 return c.json<ApiResponse>({ success: true, data: submissionList });
172 } catch (error) {
173 console.error("Get submissions error:", error);
174 return c.json<ApiResponse>({ success: false, error: "Failed to get submissions" }, 500);
175 }
176});
183
184 if (isNaN(submissionId)) {
185 return c.json<ApiResponse>({ success: false, error: "Invalid submission ID" }, 400);
186 }
187
197
198 if (result.rows.length === 0) {
199 return c.json<ApiResponse>({ success: false, error: "Submission not found" }, 404);
200 }
201
206 if (user.role === 'student') {
207 if (submissionData.user_id !== user.id) {
208 return c.json<ApiResponse>({ success: false, error: "Access denied" }, 403);
209 }
210 } else if (user.role === 'instructor') {
211 const course = await db.getCourseById(submissionData.course_id);
212 if (!course || course.instructor_id !== user.id) {
213 return c.json<ApiResponse>({ success: false, error: "Access denied" }, 403);
214 }
215 }
218 const questions = await db.getExamQuestions(submissionData.exam_id);
219
220 return c.json<ApiResponse>({
221 success: true,
222 data: {
227 } catch (error) {
228 console.error("Get submission error:", error);
229 return c.json<ApiResponse>({ success: false, error: "Failed to get submission" }, 500);
230 }
231});
239
240 if (isNaN(submissionId)) {
241 return c.json<ApiResponse>({ success: false, error: "Invalid submission ID" }, 400);
242 }
243
244 if (typeof score !== 'number' || score < 0) {
245 return c.json<ApiResponse>({ success: false, error: "Invalid score" }, 400);
246 }
247
256
257 if (result.rows.length === 0) {
258 return c.json<ApiResponse>({ success: false, error: "Submission not found" }, 404);
259 }
260
262 const course = await db.getCourseById(submissionData.course_id);
263 if (!course || course.instructor_id !== user.id) {
264 return c.json<ApiResponse>({ success: false, error: "Access denied" }, 403);
265 }
266
267 // Validate score doesn't exceed max
268 if (score > submissionData.max_score) {
269 return c.json<ApiResponse>({
270 success: false,
271 error: `Score cannot exceed maximum of ${submissionData.max_score}`
274
275 await db.updateSubmissionScore(submissionId, score, user.id);
276 return c.json<ApiResponse>({ success: true, data: { message: "Score updated successfully" } });
277 } catch (error) {
278 console.error("Grade submission error:", error);
279 return c.json<ApiResponse>({ success: false, error: "Failed to update score" }, 500);
280 }
281});

testindex.ts9 matches

@iy0rdโ€ขUpdated 4 days ago
2import { readFile, serveFile } from "https://esm.town/v/std/utils@85-main/index.ts";
3import { londonAttractions } from "./data/attractions.ts";
4import { ApiResponse, Attraction } from "../shared/types.ts";
5
6const app = new Hono();
15app.get("/shared/*", c => serveFile(c.req.path, import.meta.url));
16
17// API Routes
18app.get("/api/attractions", async (c) => {
19 const response: ApiResponse<Attraction[]> = {
20 success: true,
21 data: londonAttractions
24});
25
26app.get("/api/attractions/:id", async (c) => {
27 const id = c.req.param("id");
28 const attraction = londonAttractions.find(a => a.id === id);
29
30 if (!attraction) {
31 const response: ApiResponse<null> = {
32 success: false,
33 error: "Attraction not found"
36 }
37
38 const response: ApiResponse<Attraction> = {
39 success: true,
40 data: attraction
43});
44
45app.get("/api/attractions/category/:category", async (c) => {
46 const category = c.req.param("category");
47 const filteredAttractions = londonAttractions.filter(a => a.category === category);
48
49 const response: ApiResponse<Attraction[]> = {
50 success: true,
51 data: filteredAttractions

Reubenexams.ts24 matches

@reubenoguta_Valtownโ€ขUpdated 4 days ago
1import { Hono } from "https://esm.sh/hono@3.11.7";
2import type { CreateExamRequest, ApiResponse, Exam, Question, User, ExamAttempt } from "../../shared/types.ts";
3import * as db from "../database/queries.ts";
4import { requireAuth, requireInstructor } from "./auth.ts";
13
14 if (isNaN(courseId)) {
15 return c.json<ApiResponse>({ success: false, error: "Invalid course ID" }, 400);
16 }
17
19 const course = await db.getCourseById(courseId);
20 if (!course) {
21 return c.json<ApiResponse>({ success: false, error: "Course not found" }, 404);
22 }
23
25 const enrolled = await db.isUserEnrolled(user.id, courseId);
26 if (!enrolled) {
27 return c.json<ApiResponse>({ success: false, error: "Not enrolled in this course" }, 403);
28 }
29 } else if (user.role === 'instructor' && course.instructor_id !== user.id) {
30 return c.json<ApiResponse>({ success: false, error: "Access denied" }, 403);
31 }
32
38 : examList;
39
40 return c.json<ApiResponse<Exam[]>>({ success: true, data: filteredExams });
41 } catch (error) {
42 console.error("Get exams error:", error);
43 return c.json<ApiResponse>({ success: false, error: "Failed to get exams" }, 500);
44 }
45});
53
54 if (isNaN(courseId)) {
55 return c.json<ApiResponse>({ success: false, error: "Invalid course ID" }, 400);
56 }
57
59 const course = await db.getCourseById(courseId);
60 if (!course || course.instructor_id !== user.id) {
61 return c.json<ApiResponse>({ success: false, error: "Access denied" }, 403);
62 }
63
65
66 if (!title || !description || !duration_minutes || !questions || questions.length === 0) {
67 return c.json<ApiResponse>({ success: false, error: "All fields are required and at least one question must be provided" }, 400);
68 }
69
94 exam.total_points = totalPoints;
95
96 return c.json<ApiResponse<{ exam: Exam; questions: Question[] }>>({
97 success: true,
98 data: { exam, questions: createdQuestions }
100 } catch (error) {
101 console.error("Create exam error:", error);
102 return c.json<ApiResponse>({ success: false, error: "Failed to create exam" }, 500);
103 }
104});
111
112 if (isNaN(examId)) {
113 return c.json<ApiResponse>({ success: false, error: "Invalid exam ID" }, 400);
114 }
115
116 const exam = await db.getExamById(examId);
117 if (!exam) {
118 return c.json<ApiResponse>({ success: false, error: "Exam not found" }, 404);
119 }
120
122 const course = await db.getCourseById(exam.course_id);
123 if (!course) {
124 return c.json<ApiResponse>({ success: false, error: "Course not found" }, 404);
125 }
126
128 const enrolled = await db.isUserEnrolled(user.id, exam.course_id);
129 if (!enrolled || !exam.is_published) {
130 return c.json<ApiResponse>({ success: false, error: "Access denied" }, 403);
131 }
132 } else if (user.role === 'instructor' && course.instructor_id !== user.id) {
133 return c.json<ApiResponse>({ success: false, error: "Access denied" }, 403);
134 }
135
155 };
156
157 return c.json<ApiResponse<ExamAttempt>>({ success: true, data: examAttempt });
158 } catch (error) {
159 console.error("Get exam error:", error);
160 return c.json<ApiResponse>({ success: false, error: "Failed to get exam" }, 500);
161 }
162});
169
170 if (isNaN(examId)) {
171 return c.json<ApiResponse>({ success: false, error: "Invalid exam ID" }, 400);
172 }
173
174 const exam = await db.getExamById(examId);
175 if (!exam) {
176 return c.json<ApiResponse>({ success: false, error: "Exam not found" }, 404);
177 }
178
180 const course = await db.getCourseById(exam.course_id);
181 if (!course || course.instructor_id !== user.id) {
182 return c.json<ApiResponse>({ success: false, error: "Access denied" }, 403);
183 }
184
185 await db.publishExam(examId);
186 return c.json<ApiResponse>({ success: true, data: { message: "Exam published successfully" } });
187 } catch (error) {
188 console.error("Publish exam error:", error);
189 return c.json<ApiResponse>({ success: false, error: "Failed to publish exam" }, 500);
190 }
191});

Reubencourses.ts22 matches

@reubenoguta_Valtownโ€ขUpdated 4 days ago
1import { Hono } from "https://esm.sh/hono@3.11.7";
2import type { CreateCourseRequest, ApiResponse, Course, User } from "../../shared/types.ts";
3import * as db from "../database/queries.ts";
4import { requireAuth, requireInstructor } from "./auth.ts";
26 }
27
28 return c.json<ApiResponse<Course[]>>({ success: true, data: courseList });
29 } catch (error) {
30 console.error("Get courses error:", error);
31 return c.json<ApiResponse>({ success: false, error: "Failed to get courses" }, 500);
32 }
33});
41
42 if (!title || !description) {
43 return c.json<ApiResponse>({ success: false, error: "Title and description are required" }, 400);
44 }
45
46 const course = await db.createCourse(title, description, user.id);
47 return c.json<ApiResponse<Course>>({ success: true, data: course });
48 } catch (error) {
49 console.error("Create course error:", error);
50 return c.json<ApiResponse>({ success: false, error: "Failed to create course" }, 500);
51 }
52});
59
60 if (isNaN(courseId)) {
61 return c.json<ApiResponse>({ success: false, error: "Invalid course ID" }, 400);
62 }
63
64 const course = await db.getCourseById(courseId);
65 if (!course) {
66 return c.json<ApiResponse>({ success: false, error: "Course not found" }, 404);
67 }
68
71 const enrolled = await db.isUserEnrolled(user.id, courseId);
72 if (!enrolled) {
73 return c.json<ApiResponse>({ success: false, error: "Not enrolled in this course" }, 403);
74 }
75 course.enrolled = true;
76 } else if (user.role === 'instructor' && course.instructor_id !== user.id) {
77 return c.json<ApiResponse>({ success: false, error: "Access denied" }, 403);
78 }
79
80 return c.json<ApiResponse<Course>>({ success: true, data: course });
81 } catch (error) {
82 console.error("Get course error:", error);
83 return c.json<ApiResponse>({ success: false, error: "Failed to get course" }, 500);
84 }
85});
92
93 if (isNaN(courseId)) {
94 return c.json<ApiResponse>({ success: false, error: "Invalid course ID" }, 400);
95 }
96
97 if (user.role !== 'student') {
98 return c.json<ApiResponse>({ success: false, error: "Only students can enroll in courses" }, 403);
99 }
100
102 const course = await db.getCourseById(courseId);
103 if (!course) {
104 return c.json<ApiResponse>({ success: false, error: "Course not found" }, 404);
105 }
106
108 const alreadyEnrolled = await db.isUserEnrolled(user.id, courseId);
109 if (alreadyEnrolled) {
110 return c.json<ApiResponse>({ success: false, error: "Already enrolled in this course" }, 400);
111 }
112
113 await db.enrollUser(user.id, courseId);
114 return c.json<ApiResponse>({ success: true, data: { message: "Successfully enrolled" } });
115 } catch (error) {
116 console.error("Enroll error:", error);
117 return c.json<ApiResponse>({ success: false, error: "Failed to enroll" }, 500);
118 }
119});
126
127 if (isNaN(courseId)) {
128 return c.json<ApiResponse>({ success: false, error: "Invalid course ID" }, 400);
129 }
130
132 const course = await db.getCourseById(courseId);
133 if (!course || course.instructor_id !== user.id) {
134 return c.json<ApiResponse>({ success: false, error: "Access denied" }, 403);
135 }
136
137 const students = await db.getCourseEnrollments(courseId);
138 return c.json<ApiResponse<User[]>>({ success: true, data: students });
139 } catch (error) {
140 console.error("Get enrollments error:", error);
141 return c.json<ApiResponse>({ success: false, error: "Failed to get enrollments" }, 500);
142 }
143});

Reubenauth.ts20 matches

@reubenoguta_Valtownโ€ขUpdated 4 days ago
1import { Hono } from "https://esm.sh/hono@3.11.7";
2import { setCookie, getCookie, deleteCookie } from "https://esm.sh/hono@3.11.7/cookie";
3import type { LoginRequest, RegisterRequest, ApiResponse, User } from "../../shared/types.ts";
4import * as db from "../database/queries.ts";
5
32 // Validate input
33 if (!email || !password || !name || !role) {
34 return c.json<ApiResponse>({ success: false, error: "All fields are required" }, 400);
35 }
36
37 if (!['student', 'instructor'].includes(role)) {
38 return c.json<ApiResponse>({ success: false, error: "Invalid role" }, 400);
39 }
40
42 const existingUser = await db.getUserByEmail(email);
43 if (existingUser) {
44 return c.json<ApiResponse>({ success: false, error: "User already exists" }, 400);
45 }
46
64 // Remove password hash from response
65 const { password_hash, ...userResponse } = user as any;
66 return c.json<ApiResponse<User>>({ success: true, data: userResponse });
67 } catch (error) {
68 console.error("Registration error:", error);
69 return c.json<ApiResponse>({ success: false, error: "Registration failed" }, 500);
70 }
71});
78
79 if (!email || !password) {
80 return c.json<ApiResponse>({ success: false, error: "Email and password are required" }, 400);
81 }
82
84 const user = await db.getUserByEmail(email);
85 if (!user) {
86 return c.json<ApiResponse>({ success: false, error: "Invalid credentials" }, 401);
87 }
88
89 const passwordHash = await db.getUserPasswordHash(email);
90 if (!passwordHash || !(await verifyPassword(password, passwordHash))) {
91 return c.json<ApiResponse>({ success: false, error: "Invalid credentials" }, 401);
92 }
93
105 });
106
107 return c.json<ApiResponse<User>>({ success: true, data: user });
108 } catch (error) {
109 console.error("Login error:", error);
110 return c.json<ApiResponse>({ success: false, error: "Login failed" }, 500);
111 }
112});
121
122 deleteCookie(c, "session");
123 return c.json<ApiResponse>({ success: true });
124 } catch (error) {
125 console.error("Logout error:", error);
126 return c.json<ApiResponse>({ success: false, error: "Logout failed" }, 500);
127 }
128});
133 const sessionId = getCookie(c, "session");
134 if (!sessionId) {
135 return c.json<ApiResponse>({ success: false, error: "Not authenticated" }, 401);
136 }
137
138 const user = await db.getSessionUser(sessionId);
139 if (!user) {
140 return c.json<ApiResponse>({ success: false, error: "Invalid session" }, 401);
141 }
142
143 return c.json<ApiResponse<User>>({ success: true, data: user });
144 } catch (error) {
145 console.error("Get user error:", error);
146 return c.json<ApiResponse>({ success: false, error: "Failed to get user" }, 500);
147 }
148});
152 const sessionId = getCookie(c, "session");
153 if (!sessionId) {
154 return c.json<ApiResponse>({ success: false, error: "Authentication required" }, 401);
155 }
156
157 const user = await db.getSessionUser(sessionId);
158 if (!user) {
159 return c.json<ApiResponse>({ success: false, error: "Invalid session" }, 401);
160 }
161
168 const user = c.get("user");
169 if (!user || user.role !== 'instructor') {
170 return c.json<ApiResponse>({ success: false, error: "Instructor access required" }, 403);
171 }
172 await next();

Reubentypes.ts2 matches

@reubenoguta_Valtownโ€ขUpdated 4 days ago
81}
82
83// API Response types
84export interface ApiResponse<T = any> {
85 success: boolean;
86 data?: T;

ReubenREADME.md17 matches

@reubenoguta_Valtownโ€ขUpdated 4 days ago
37โ”‚ โ”‚ โ”œโ”€โ”€ submissions.ts # Exam submissions
38โ”‚ โ”‚ โ””โ”€โ”€ static.ts # Static file serving
39โ”‚ โ””โ”€โ”€ index.ts # Main API server
40โ”œโ”€โ”€ frontend/
41โ”‚ โ”œโ”€โ”€ components/
61## Technology Stack
62
63- **Backend**: Hono.js API framework
64- **Database**: SQLite with automatic migrations
65- **Frontend**: React with TypeScript
67- **Authentication**: Session-based auth with secure cookies
68
69## API Endpoints
70
71### Authentication
72- `POST /api/auth/register` - User registration
73- `POST /api/auth/login` - User login
74- `POST /api/auth/logout` - User logout
75- `GET /api/auth/me` - Get current user
76
77### Courses
78- `GET /api/courses` - List all courses
79- `POST /api/courses` - Create new course (instructors only)
80- `GET /api/courses/:id` - Get course details
81- `POST /api/courses/:id/enroll` - Enroll in course
82
83### Exams
84- `GET /api/courses/:id/exams` - List course exams
85- `POST /api/courses/:id/exams` - Create new exam
86- `GET /api/exams/:id` - Get exam details
87- `POST /api/exams/:id/submit` - Submit exam answers
88
89### Submissions
90- `GET /api/exams/:id/submissions` - Get exam submissions (instructors)
91- `GET /api/submissions/:id` - Get specific submission details

testtypes.ts1 match

@iy0rdโ€ขUpdated 4 days ago
39}
40
41export interface ApiResponse<T> {
42 success: boolean;
43 data?: T;

Advertappindex.ts7 matches

@Raj3bโ€ขUpdated 4 days ago
19await runMigrations();
20
21// API routes
22app.route('/api/auth', authRoutes);
23app.route('/api/advertisements', advertisementRoutes);
24app.route('/api/leads', leadRoutes);
25app.route('/api/followups', followupRoutes);
26app.route('/api/orders', orderRoutes);
27app.route('/api/debug', debugRoutes);
28
29// Static file serving and main app

zerodha_pull_holdingsmain.tsx7 matches

@tinfoil_knightโ€ขUpdated 4 days ago
5import { parse as parseQuery } from "npm:querystring";
6
7const apiKey = process.env.API_KEY;
8const apiSecret = process.env.API_SECRET;
9const username = process.env.USERNAME;
10const password = process.env.PASSWORD;
11const totpKey = process.env.TOTP_KEY;
12const loginUrl = `https://kite.zerodha.com/connect/login?v=3&api_key=${apiKey}`;
13
14export default async function(interval: Interval) {
16 console.log("requestToken", requestToken);
17
18 const kc = new KiteConnect({ api_key: apiKey });
19
20 async function generateSession() {
21 try {
22 const response = await kc.generateSession(requestToken, apiSecret);
23 kc.setAccessToken(response.access_token);
24 console.log("Session generated:", response);
57
58 // Step 2: Login request
59 const loginRes = await fetch("https://kite.zerodha.com/api/login", {
60 method: "POST",
61 headers: { "Content-Type": "application/x-www-form-urlencoded" },
77 });
78
79 await fetch("https://kite.zerodha.com/api/twofa", {
80 method: "POST",
81 headers: { "Content-Type": "application/x-www-form-urlencoded" },

Apiify9 file matches

@wolfโ€ขUpdated 15 mins ago

dailyQuoteAPI

@Soukyโ€ขUpdated 2 days ago
Kapil01
apiv1