Skip to content

henryamster/LinkGen

Repository files navigation

LinkGen - Secure Markdown Sharing

image

A TypeScript-based web application for sharing markdown documents with configurable expiry dates, view limits, file attachments, and admin management.

✨ Features

  • πŸ”’ Secure Sharing: Documents are stored temporarily and automatically deleted
  • ⏰ Time-based Expiry: Set documents to expire after 1-168 hours
  • πŸ‘οΈ View Limits: Configure maximum number of views (1-100)
  • πŸ“ Markdown Support: Full markdown rendering with syntax highlighting
  • πŸ“Ž File Attachments: Upload files up to 10MB each
  • 🎨 Material Design 3: Modern, clean interface with Material Icons
  • πŸ”„ HTML Import: Convert HTML content to markdown
  • πŸ‘¨β€πŸ’Ό Admin Panel: Secure admin interface for document management
  • ⚑ TypeScript: Fully typed frontend and backend
  • πŸ—οΈ IIS Ready: Deployment package for Windows IIS

πŸš€ Quick Start

Development Mode

  1. Install dependencies:

    npm install
  2. Start development servers:

    npm run dev

    This runs both the frontend (port 5173) and backend (port 3001) concurrently.

  3. Open your browser: Navigate to http://localhost:5173

Production Build

  1. Build the application:
    npm run start

IIS Deployment

  1. Build deployment package:

    npm run build:iis
  2. Deploy to Windows IIS: See IIS Deployment Guide for detailed instructions.

πŸ“– Usage

Creating a Document

  1. Add Content:

    • Paste markdown content in the text area, or
    • Upload files using the attachment button, or
    • Convert HTML content to markdown
  2. Configure Settings:

    • Set maximum number of views (1-100)
    • Set expiry time in hours (1-168, max 1 week)
    • Add an optional title
  3. Generate Link:

    • Click "Generate Secure Link"
    • Share the generated URL

Admin Panel

image
  1. Access Admin: Navigate to /admin and enter admin password (default: admin123)

  2. Manage Documents:

    • View all active documents
    • See view counts and expiry times
    • Monitor system usage

Viewing a Document

image
  • Navigate to the generated URL
  • The document will be displayed with proper markdown formatting
  • View count decreases with each access
  • Document is automatically deleted when expired or view limit reached

πŸ”Œ API Endpoints

Document Management

POST /api/upload

Create a new document with optional file attachments.

Content-Type: application/json or multipart/form-data

Request Body (JSON):

{
  "content": "# Your markdown content here",
  "maxViews": 1,
  "expiryHours": 24,
  "title": "Optional document title",
  "attachmentIds": ["uuid1", "uuid2"]
}

Request Body (FormData with files):

content: "# Your markdown content"
maxViews: "1"
expiryHours: "24"
title: "Optional title"
files: [File objects]

Response:

{
  "success": true,
  "id": "uuid-string",
  "url": "https://your-domain.com/view/uuid-string",
  "expiryDate": "2024-01-01T00:00:00.000Z",
  "maxViews": 1,
  "attachmentCount": 2
}

GET /api/document/:id

Retrieve a document by ID (decrements view count).

Response:

{
  "success": true,
  "content": "# Your markdown content",
  "remainingViews": 0,
  "expiryDate": "2024-01-01T00:00:00.000Z",
  "title": "Document title",
  "attachments": [
    {
      "id": "uuid",
      "filename": "file.pdf",
      "mimetype": "application/pdf",
      "size": 1024,
      "url": "/api/attachment/uuid"
    }
  ]
}

File Management

POST /api/upload-file

Upload a single file for later attachment to documents.

Content-Type: multipart/form-data

GET /api/attachment/:id

Download an attachment file.

Admin Endpoints

POST /api/admin/login

Authenticate admin user.

GET /api/admin/documents

Get list of all active documents (requires admin auth).

πŸ“ Project Structure

linkgen/
β”œβ”€β”€ backend/
β”‚   β”œβ”€β”€ server.ts             # Main production server
β”‚   └── server-dev.ts         # Development server (simplified)
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ main.ts              # Frontend TypeScript application
β”‚   └── style.css            # Application styles
β”œβ”€β”€ public/                  # Static assets
β”œβ”€β”€ build-iis.js            # IIS deployment build script
β”œβ”€β”€ build-iis.ps1           # PowerShell build script
β”œβ”€β”€ deploy-iis.sh           # Quick deployment script
β”œβ”€β”€ index.html              # Main HTML template
β”œβ”€β”€ package.json            # Dependencies and scripts
β”œβ”€β”€ tsconfig.json           # TypeScript configuration
β”œβ”€β”€ vite.config.ts          # Vite build configuration
β”œβ”€β”€ README.md               # This file
└── README-IIS-DEPLOYMENT.md # IIS deployment guide

Build Outputs

dist/                       # Built frontend (after npm run build)
dist-server/               # Built backend (after npm run server:build)
deploy/                    # IIS deployment package (after npm run build:iis)

πŸ”’ Security Features

  • Temporary Storage: Documents stored in memory only (not persisted to disk)
  • Automatic Cleanup: Expired documents removed every 5 minutes
  • View Count Enforcement: Documents deleted after max views reached
  • Input Validation: All endpoints validate input data and file types
  • Admin Authentication: JWT-based admin sessions with configurable passwords
  • File Size Limits: 10MB maximum per file upload
  • CORS Protection: Configurable cross-origin request handling
  • Request Size Limits: Protection against large payload attacks

πŸ› οΈ Technologies

Frontend

  • TypeScript: Type-safe development
  • Vite: Fast build tool and dev server
  • Material Design 3: Modern UI components and styling
  • Material Symbols: Consistent iconography
  • Marked: Markdown parsing and rendering
  • Turndown: HTML to markdown conversion

Backend

  • Node.js + Express: Server framework
  • TypeScript: Full type safety
  • Multer: File upload handling
  • bcryptjs: Password hashing
  • jsonwebtoken: Admin authentication
  • UUID: Unique document identification

Development

  • tsx: TypeScript execution for development
  • concurrently: Run multiple dev processes
  • Vite: Hot module replacement

βš™οΈ Configuration

Environment Variables

Development

PORT=3001                    # Server port (default: 3001)

Production/IIS

PORT=80                      # Server port
ADMIN_PASSWORD=your-password # Admin panel password (default: admin123)
JWT_SECRET=your-jwt-secret   # Secret for JWT tokens (change in production!)
NODE_ENV=production          # Environment mode
IISNODE_PORT=80             # IIS-specific port (when using iisnode)

Application Limits

  • Maximum views per document: 100
  • Maximum expiry time: 168 hours (1 week)
  • Maximum file size: 10MB per file
  • Document cleanup interval: 5 minutes
  • Maximum request body size: 10MB

Development vs Production

Development Server (server-dev.ts)

  • Simplified routing for faster development
  • Enhanced logging for debugging
  • Automatic TypeScript compilation with tsx
  • CORS enabled for local development

Production Server (server.ts)

  • Full feature set with admin authentication
  • Environment-based configuration
  • Optimized for deployment
  • Enhanced security features

πŸš€ Deployment Options

1. IIS (Windows Server)

Use the built-in IIS deployment scripts:

npm run build:iis           # Create deployment package
./deploy-iis.sh            # Quick deploy script

See README-IIS-DEPLOYMENT.md for detailed instructions.

2. Standard Node.js Hosting

For platforms like Heroku, Railway, DigitalOcean, etc.:

npm run build              # Build frontend
npm run server:build       # Build backend
npm start                  # Start production server

3. Local Production

npm run start              # Build and start locally

License

MIT License - feel free to use this project for your own needs!

About

Secure temporary sharing for markdown/small files with in-memory or persistent storage

Resources

Security policy

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published