forked from jason/cpolis
		
	Compare commits
	
		
			3 Commits
		
	
	
		
			faa69ed9a9
			...
			351a1d2f77
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 351a1d2f77 | |||
| f68241c092 | |||
| 9519ad5a1e | 
@@ -345,6 +345,33 @@ func (db *DB) DeleteArticle(id int64) error {
 | 
			
		||||
	return nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (db *DB) GetAllArticles() ([]*Article, error) {
 | 
			
		||||
	query := `
 | 
			
		||||
    SELECT title, created, banner_link, summary, published, creator_id, issue_id, edited_id, clicks, is_in_issue, auto_generated, uuid
 | 
			
		||||
    FROM articles
 | 
			
		||||
    `
 | 
			
		||||
 | 
			
		||||
	rows, err := db.Query(query)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return nil, fmt.Errorf("error querying DB: %v", err)
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	articles := make([]*Article, 0)
 | 
			
		||||
	for rows.Next() {
 | 
			
		||||
		article := new(Article)
 | 
			
		||||
		if err = rows.Scan(&article.Title, &article.Created, &article.BannerLink, &article.Summary, &article.Published, &article.CreatorID, &article.IssueID, &article.EditedID, &article.Clicks, &article.IsInIssue, &article.AutoGenerated, &article.UUID); err != nil {
 | 
			
		||||
			return nil, fmt.Errorf("error scanning rows: %v", err)
 | 
			
		||||
		}
 | 
			
		||||
		articles = append(articles, article)
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	if err := rows.Err(); err != nil {
 | 
			
		||||
		return nil, fmt.Errorf("error iterating over rows: %v", err)
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	return articles, nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func WriteArticleToFile(c *Config, articleUUID uuid.UUID, content []byte) error {
 | 
			
		||||
	articlePath := filepath.Join(c.ArticleDir, fmt.Sprint(articleUUID, ".md"))
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -55,7 +55,7 @@ func newConfig() *Config {
 | 
			
		||||
		MaxImgWidth:       1920,
 | 
			
		||||
		PDFDir:            "/var/www/cpolis/pdfs",
 | 
			
		||||
		Port:              ":1664",
 | 
			
		||||
		Version:           "v0.16.0",
 | 
			
		||||
		Version:           "v0.16.1",
 | 
			
		||||
		WebDir:            "/var/www/cpolis/web",
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -56,7 +56,20 @@ func checkImageUsage(c *Config, db *DB, name string) (bool, error) {
 | 
			
		||||
 | 
			
		||||
		for _, user := range users {
 | 
			
		||||
			if name == user.ProfilePicLink {
 | 
			
		||||
				return true, nil
 | 
			
		||||
				imageWasFound = true
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	if !imageWasFound {
 | 
			
		||||
		articles, err := db.GetAllArticles()
 | 
			
		||||
		if err != nil {
 | 
			
		||||
			return false, fmt.Errorf("error getting all articles: %v", err)
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		for _, article := range articles {
 | 
			
		||||
			if name == article.BannerLink {
 | 
			
		||||
				imageWasFound = true
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user